如何结合 codeigniter 和 angularjs?

how to combine codeigniter and angularjs?

我看过很多关于 codeigniter 和 angularjs 一起工作的帖子,但大多数都是关于检索数据和传递数据的。我的问题更基本。

我 运行 通过 php 站点,然后一切正常,意味着 angularjs 当我通过控制器 运行 它时 properly.But 工作, work.what 没有错吗?以下是我的部分代码:

<body ng-app="myApp" ng-controller="myCtrl">

First Name: <input type="text" ng-model="firstName"><br>
Last Name: <input type="text" ng-model="lastName"><br>
<br>
Full Name: {{firstName + " " + lastName}}

class First extends CI_Controller{

  public function index(){
      $this->load->view('first');
  }

}

var app = angular.module('myApp', ['ngMaterial']);
app.controller('myCtrl', function($scope) {
    $scope.firstName = "John";
    $scope.lastName = "Doe";
});

我的控制器文件是 first.php,查看文件是 first.php as well.when 我通过 http://localhost/ci_ngtest/index.php/first 浏览网站,输入的名字和姓氏都是空白的,并且全名显示 {{firstName + " " + lastName}} 而不是 John Doe


这是我的项目结构:

 --application
 --node_modules
   --angular
     --angular.js
   --angular-material
 --system
 --user_guide
 --somefiles(somefiles below)

您需要正确配置脚本路径:

  1. 先在application\config\config里面设置base_url。php:

$config['base_url']= 'http://localhost/ci_ngtest/index.php/';

  1. 在 application\config\autoload.php
  2. 中加载库

$autoload['helper'] = array('url');

  1. 配置脚本路径:

<script src="<?php echo base_url();?>node_modules/angular/angular.js"></script> <script src="<?php echo base_url();?>node_modules/angular-material/angular-material.js"></script>