猿问

angular中控制器名的问题?

html:

<div ng-controller="FilterController as ctrl">

js:

angular.module('FilterInControllerModule', []).

controller('FilterController', ['filterFilter', function(filterFilter) {

this.array = [

{name: 'asnowwolf'},

{name: 'why520crazy'},

{name: 'joe'},

{name: 'ckken'},

{name: 'lightma'},

{name: 'FrankyYang'}

];

this.filteredArray = filterFilter(this.array, 'a');

}]);

这样可以通过ctrl.array来访问FilterController控制器里的array数组,可是我通过FilterController.array却访问不了,这是为什么?还有FilterController控制器里的this是不是指FilterController?


慕盖茨0887536
浏览 1420回答 1
1回答

习惯受伤

1.问题出在"FilterController as ctrl",相当于实例化了一个controller,实例名位ctrl,所以你需要通过ctrl.array来访问。2.this指FilterController
随时随地看视频慕课网APP
我要回答