我正在使用controller as
语法构建Angular控制器:
<body ng-controller="ctrl as myCtrl">
<p>accessed via scope resolution: {{ foo }} </p>
<p>accessed via controller resolution: {{ myCtrl.foo }}</p>
</body>
在控制器中我有这个:
myApp.controller('ctrl', function($scope) {
this.foo = 'Controller\'s foo';
$scope.foo = '$scope\'s foo';
});
上面的代码适用于打印机器人controller's foo
和$scope's foo
。