0
如果您會看到代碼,您會注意到我將template
屬性設置爲{{$.aaa}}
。有沒有辦法避免在變量前使用controllerAs
前綴,並使用表格{{aaa}}
的模板?使用不帶「controllerAs」前綴的模板
(function(){
"use strict";
class Controller {
constructor(){
this.aaa = 111;
}
doSomething(){
alert(this.aaa)
}
}
var app = angular.module('app', []);
app.directive('any', function() {
return {
restrict: 'E',
controller: Controller,
controllerAs: '$',
template: '{{$.aaa}}'
};
});
})();
應該是$範圍的財產不屬於控制器。請注意,現在控制器的語法是首選方式。 –