我想要定制textAngular指令选项。
API 文档说我应该设置 $rootScope.textAngularTools.{customButton} 来构建函数。
但是如果我在 Controller 上设置,指令会告诉我属性未定义。
如果我在 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 : {}
关于javascript - 在 textAngular 指令初始之前设置 $rootScope,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21188292/