我是 angularjs 的新手,我一直在尝试一些基本教程,我注意到 Controller 的声明和使用方式存在一些差异,因此我想澄清一下 ,例如在此 JSfiddle 链接中 - http://jsfiddle.net/dakra/U3pVM/用户已将 Controller 定义为函数名称,该函数名称在 1.0.3 版本中工作得很好。我正在使用 1.3.15 版本的 Angular,这种方法对我不起作用
<html ng-app="myapp">
AngularJS 数据绑定(bind)
<div data-ng-controller="SimpleController">
Name :
<br/>
<input type="text" ng-model="name"/>{{name |uppercase}}
<div>
<ul>
<li ng-repeat="personName in names">{{personName}}</li>
</ul>
</div>
</div>
<script src="node_modules/angular/angular.min.js"></script>
<script>
function SimpleController($scope) {
$scope.names =['test1','test2','new'];
}
上面的代码不起作用,因为它显示 SimpleController 是未定义函数的错误。
当我添加此代码而不是上面的函数时,它可以工作 -
var app = angular.module('myApp', []);
app.controller('SimpleController', function($scope) {
$scope.names = ['test1','test2'];
});
谢谢
最佳答案
通过以下方式简单声明 Controller
function MyCtrl($scope) {
}
在 Angular 1.3 中被删除。重大变更:http://wildermuth.com/2014/11/11/Angular_1_3_and_Breaking_Change_for_Controllers
关于javascript - AngularJS Controller 功能歧义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30624885/