.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/user/myCtrl', {
templateUrl: 'user/myCtrl.html',
controller: 'myCtrl',
controllerAs:'vm' //第一步:加上controllerAs参数。vm 是 View Model 的简写。
})
}])
myApp.controller("myCtrl",function(){ //注意这里不用注入$scope了
//第二步:为了避免this指向改变造成的问题并且使用起来更加方便,将this转存
var vm= this;
vm.属性名 = 值;
vm.函数名 = function(){
};
});
//第三步:在变量前,别忘了加上别名vm来访问数据
<input type="password" class="form-control" ng-model="vm.pwd" required>
angularjs 传统的写法换成controllerAs语法
猜你喜欢
转载自blog.csdn.net/weixin_42971942/article/details/84899172
今日推荐
周排行