我已经使用angular 1.5 -1.6项目等切换到控制器作为语法... 我需要为角度1.4.5项目添加一些功能的特定项目。
通常我使用角度路由等..但是这个项目设置不同。
问题出现在我的模板html中,我能够看到
$scope.blah // {{ blah}}
但我不明白为什么或如何访问this
控制器:
icisNg.controller("hearingListing", ['$scope', '$rootScope',
function ($scope, $rootScope) {
$scope.blah = 333;
var vm = this;
vm.whatever = 'controller as';
$scope.atEnd = "endsdfgsdfgsdfg";
console.log('scope', $scope.atEnd);
console.log('vm', vm.whatever);
}
]);
Html模板:
<div fieldset-wrapper legend="Hearing" ng-controller="hearingListing">
<div>test again</div>
<div>{{blah}}</div>
eewr
<br />
vm:{{vm.whatever}}
<br />
{{atEnd}}
</div>
答案 0 :(得分:1)
根据您的代码呈现方式,最权宜之计是......
更改强>
ng-controller="hearingListing"
要强>
ng-controller="hearingListing as vm"
===
另外,请注意控制器中的变量vm
不会引用模板中的相同vm
。它们是不同的,可以命名。