[英]AngularJS controller function ambiguity
I am new to angularjs and I have been trying out few basic tutorials and I noticed some discrepancy on how controller is declared and used thus I wanted clarification , for example in this JSfiddle link - http://jsfiddle.net/dakra/U3pVM/ the user has defined the controller as the function name which works perfectly fine for version 1.0.3 . 我是angularjs的新手,我一直在尝试一些基本的教程,但我注意到在声明和使用控制器的方式上存在一些差异,因此我想澄清一下,例如在此JSfiddle链接中-http: //jsfiddle.net/dakra/U3pVM/用户已将控制器定义为功能名称,该功能在1.0.3版本中可以正常使用。 I am using 1.3.15 version of angular and this approach isn't working for me
我正在使用1.3.15版本的angular,这种方法对我不起作用
<html ng-app="myapp">
AngularJS data binding AngularJS数据绑定
<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'];
}
The above code just isn't working as it's showing an error of SimpleController being undefined function. 上面的代码不起作用,因为它显示了SimpleController是未定义函数的错误。
where as when I add this code instead of the above function, it works - 当我添加此代码而不是上述功能时,它的工作原理是-
var app = angular.module('myApp', []);
app.controller('SimpleController', function($scope) {
$scope.names = ['test1','test2'];
});
Thanks, 谢谢,
The simple declaration of controllers via 通过以下方式简单声明控制器
function MyCtrl($scope) {
}
was removed in Angular 1.3. 已在Angular 1.3中删除。 Breaking changes: http://wildermuth.com/2014/11/11/Angular_1_3_and_Breaking_Change_for_Controllers
重大更改: http : //wildermuth.com/2014/11/11/Angular_1_3_and_Breaking_Change_for_Controllers
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.