我正在使用 angular.layout 库 ( https://github.com/angular-ui/ui-layout )。我想从指令中手动切换面板。
它是库中的 Controller :
...
angular.module('ui.layout', [])
.controller('uiLayoutCtrl', ['$scope', '$attrs', '$element', 'LayoutContainer', function uiLayoutCtrl($scope, $attrs, $element, LayoutContainer)
...
这个 Controller 有方法 ctrl.toggleAfter
和 ctrl.toggleBefore
。
所以,问题是:如何在我自己的指令中使用它。我试过这种方式:
...
return {
require: 'uiLayoutCtrl',
link: function(scope, element, attrs, ctrl) {
...
}
}
...
它不起作用。
谢谢!
最佳答案
尝试要求指令而不是 Controller :
require: 'uiLayout', // both directives in the same element // OR
//require: '^uiLayout' // your directive is a child of uiLayout
link: function (scope, elm, attr, ctrl) {
// ctrl should be uiLayoutCtrl
}
关于javascript - 以 Angular 从不同模块访问 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30372402/