[英]When I set angularjs directive templateUrl $rootScope event does not populate
[英]Set $rootScope before textAngular directive initial
我想自定義textAngular指令選項。
API文檔說我應該設置$ rootScope.textAngularTools。{customButton}來構建一個函數。
但是,如果我在控制器上設置,指令將告訴我屬性未定義。
如果我在module.run函數中設置,$ rootScope.textAngularTools是未定義的。
如何在指令初始化之前設置選項?
<text-angular to-toolbar="[['customButton']]">
設置如下(coffeescript)
$rootScope.textAngularTools.colourRed =
display: "<button ng-click='action()' ng-class='displayActiveToolClass(active)'><i class='fa fa-square' style='color: red;'></i></button>",
action: ->
console.log 'action'
activeState: ->
false
從閱讀來源我建議你在模塊運行功能中進行配置:
angular.modul('myApp', ['textAngular'])
.run(function($rootScope){
$rootScope.textAngularTools = {
colourRed: {
display: "<button ng-click='action()' ng-class='displayActiveToolClass(active)'><i class='fa fa-square' style='color: red;'></i></button>",
action: function(){
console.log('action);
}
}
};
})
.controller('yourController')...
為什么要這樣做? 它們在其指令中擴展了現有的textAngularTools對象:
$rootScope.textAngularTools != null)? $rootScope.textAngularTools : {}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.