角度引导添加新指令不起作用
angular-bootstrap add new directive dosn't work
我想在ui.boostrap.accordion模块中创建一个新指令,以避免手风琴打开点击事件。
我在另一个文件中有以下代码.js:
angular.module('ui.bootstrap.accordion')
.directive('accordionGroupLazyOpen', function() {
return {
require: '^accordion',
restrict: 'EA',
transclude: true,
replace: true,
templateUrl: function(element, attrs) {
return attrs.templateUrl || 'template/accordion/accordion-group.html';
},
scope: {
heading: '@',
isOpen: '=?',
isDisabled: '=?'
},
controller: function() {
this.setHeading = function(element) {
this.heading = element;
};
},
link: function(scope, element, attrs, accordionCtrl) {
accordionCtrl.addGroup(scope);
scope.openClass = attrs.openClass || 'panel-open';
scope.panelClass = attrs.panelClass;
scope.$watch('isOpen', function(value) {
element.toggleClass(scope.openClass, value);
if (value) {
accordionCtrl.closeOthers(scope);
}
});
scope.toggleOpen = function($event) {
};
}
};
})
问题是当我执行应用程序时,出现以下错误:
控制器"手风琴组", 指令要求 "手风琴排除",找不到!
错误链接
有什么想法吗?
正如我从源代码中看到的(也许不是你的版本,但仍然是一样的):
// Use in the accordion-group template to indicate where you want the heading to be transcluded
// You must provide the property on the accordion-group controller that will hold the transcluded element
.directive('uibAccordionTransclude', function() {
return {
require: '^uibAccordionGroup', // <- look at this line in your version
link: function(scope, element, attrs, controller) {
scope.$watch(function() { return controller[attrs.uibAccordionTransclude]; }, function(heading) {
if (heading) {
element.find('span').html('');
element.find('span').append(heading);
}
});
}
};
所以我想它试图在视图中找到与accordionGroup
匹配的父指令,但由于您添加了accordionGroupLazyOpen
而不是accordionGroup
,因此它找不到它。
在您提供的错误页面中指出:
当 HTML 编译器尝试处理 在指令定义中指定 require 选项,但 当前 DOM 上不存在所需的指令控制器 元素(或其祖先元素,如果指定了 ^)。
如果您查看accordion-group-template
文件,您将看到 accordionTransclude
指令在那里被调用。
相关文章:
- 新的自定义角度指令不起作用
- AngularJS,自定义指令不起作用@ plnkr
- AngularJS + Coffeescript - 'Hello World' 指令不起作用
- 使用 $provide 重命名第三方角度指令 - 不起作用
- 带有指令不起作用的 AngularJS 动态表单字段 ID
- AngularJS:双向数据绑定 - 带有ng重复的指令 - 不起作用
- 为什么我在 AngularJs 中的指令不起作用
- 剑道指令不起作用
- ng-单击指令不起作用
- 为什么这个 angularjs 指令不起作用
- 角度引导添加新指令不起作用
- AngularJS + Facebook喜欢指令不起作用
- 带有 ngModel 绑定的 AngularJS 自定义指令不起作用
- Angularjs 指令不起作用“意外令牌”
- jQuery插件中的Angular指令不起作用
- 可重复使用的按钮指令不起作用
- Angular JS自定义指令不起作用
- 带有编译函数和ng-show的角度对话框指令不起作用
- 一个元素上的多个指令不起作用
- AngularJS:drag-n-drop指令不起作用