3
我實際上創建了一個小指令,而且我正面臨着作用域對象和controllAs的問題。角控制器As和參數
其實,我有這樣的結果:
angular.module('app')
.directive('historyConnection', function() {
return {
templateUrl: 'views/directives/historyconnection.html',
restrict: 'E',
scope: {
idUser: '@iduser'
},
controller:function($scope){
console.log(this.idUser); // gives undefined
console.log($scope.idUser); // gives the good value
},
controllerAs:'history'
};
});
從HTML代碼:
<history-connection iduser="55"></history-connection>
我不知道如何使controllerAs工作參數傳遞給指令時。你可以幫我嗎 ?如果你想在作用域屬性綁定到你必須添加bindToController: true
該指令定義控制器
重要信息被註釋掉在JavaScript代碼上面
我強烈建議你這個帖子http://blog.thoughtram.io/angularjs/2015/01/02/exploring-angular-1.3-bindToController.html –
看到這個; http://jsfiddle.net/9ny4ujb5/ –
有一些解釋:http://www.ng-newsletter.com/posts/directives.html –