我试图了解为什么我必须使用as
为了双向绑定将与控制器内的this
。角度控制器作为NewController 2方式绑定与this.function
工作示例:
<div ng-controller="MyController as TestController">
{{TestController.test()}}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('MyController', function(){
this.test = function test(){
return "test";
};
});
</script>
不灵例如:
<div ng-controller="MyController">
{{MyController.test()}}
</div>
<script>
var app = angular.module('myApp', []);
app.controller('MyController', function(){
this.test = function test(){
return "test";
};
});
</script>
你不了解它吗?使用'as'允许在'$ digest'循环中进行双向绑定。否则,角度将不会在控制器上有句柄。 – 2015-02-09 11:39:13
https://docs.angularjs.org/guide/concepts#controller – paje007 2015-02-09 11:45:12