编译错误,需要手风琴控制器 [英] compile error, accordion controller required
问题描述
我在使用 angular-bootstrap ui 时在控制台中遇到以下错误.我有 angular 1.2.6、bootstrap 3.0 和 angular-bootstrap 0.10.0.
错误:[$compile:ctreq] 无法找到指令accordionGroup"所需的控制器accordion"!
有人知道为什么会这样吗?我的 html 代码.
<accordion-group id="crud-talbe" ng-repeat="grid in grids" Heading="{{grid.name}}"><a ng-click="createNewEntity(grid.name)" class="btn btn-default">创建新的{{grid.name}}</a><div class="crudGridStyle" ng-grid="grid"/></accordion-group> 解决方案 从您提供的代码来看,您没有包含足够的 ui-bootstrap 所需的代码.
这看起来是您需要的最少数量以及编译器给出错误的原因.
<accordion-group Heading="静态标题,初始展开" is-open="true">此内容直接在模板中.</accordion-group></手风琴>
这是直接从 ui-bootstrap 网站...手风琴部分.
您可以看到在手风琴组指令的代码中需要手风琴...
来自 github:>
//手风琴组指令指示将在手风琴中展开和折叠的 html 块.directive('accordionGroup', function() {返回 {require:'^accordion',//我们需要在手风琴中使用这个指令限制:'EA',transclude:true,//将指令的内容嵌入到模板中replace: true,//包含指令的元素将被模板替换templateUrl:'template/accordion/accordion-group.html',范围: {Heading: '@',//将heading 属性插入到这个范围内isOpen: '=?',isDisabled: '=?'},控制器:函数(){this.setHeading = 函数(元素){this.heading = 元素;};},链接:功能(范围,元素,属性,手风琴Ctrl){手风琴Ctrl.addGroup(范围);scope.$watch('isOpen', function(value) {如果(值){手风琴Ctrl.closeOthers(范围);}});scope.toggleOpen = function() {如果(!scope.isDisabled){scope.isOpen = !scope.isOpen;}};}};})
I met following error in the console when using angular-bootstrap ui. I have angular 1.2.6, bootstrap 3.0, and angular-bootstrap 0.10.0.
Error: [$compile:ctreq] Controller 'accordion', required by directive 'accordionGroup', can't be found!
Anyone know why it happens?
My html code.
<div ui-view>
<accordion-group id="crud-talbe" ng-repeat="grid in grids" heading="{{grid.name}}">
<a ng-click="createNewEntity(grid.name)" class="btn btn-default">create new {{grid.name}}</a>
<div class="crudGridStyle" ng-grid="grid" />
</accordion-group>
解决方案 From the code you have provided, you aren't including enough of the required code from ui-bootstrap.
This looks like the minimum of what you need and why the compiler is giving the error.
<accordion close-others="oneAtATime">
<accordion-group heading="Static Header, initially expanded" is-open="true">
This content is straight in the template.
</accordion-group>
</accordion>
This is straight off the ui-bootstrap site... accordion section.
You can see that in the accordion group directive's code that the accordion is required...
From github:
// The accordion-group directive indicates a block of html that will expand and collapse in an accordion
.directive('accordionGroup', function() {
return {
require:'^accordion', // We need this directive to be inside an accordion
restrict:'EA',
transclude:true, // It transcludes the contents of the directive into the template
replace: true, // The element containing the directive will be replaced with the template
templateUrl:'template/accordion/accordion-group.html',
scope: {
heading: '@', // Interpolate the heading attribute onto this scope
isOpen: '=?',
isDisabled: '=?'
},
controller: function() {
this.setHeading = function(element) {
this.heading = element;
};
},
link: function(scope, element, attrs, accordionCtrl) {
accordionCtrl.addGroup(scope);
scope.$watch('isOpen', function(value) {
if ( value ) {
accordionCtrl.closeOthers(scope);
}
});
scope.toggleOpen = function() {
if ( !scope.isDisabled ) {
scope.isOpen = !scope.isOpen;
}
};
}
};
})
这篇关于编译错误,需要手风琴控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文