Javascript AngularJS:$decorator将新变量绑定到指令
我正在使用装饰器将变量添加到指令的隔离范围。但不知怎么的,它不起作用,我几乎什么都试过了 确切的指令是angular ui的一个:Javascript AngularJS:$decorator将新变量绑定到指令,javascript,angularjs,angular-ui,Javascript,Angularjs,Angular Ui,我正在使用装饰器将变量添加到指令的隔离范围。但不知怎么的,它不起作用,我几乎什么都试过了 确切的指令是angular ui的一个: .directive('accordionGroup', function() { return { require:'^accordion', // We need this directive to be inside an accordion restrict:'EA', transclude:true,
.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: '=?'
},
...
})
$decorator代码(我用来更改模板并添加新变量)是:
mainModule.config(['$provide', function ($provide){
$provide.decorator('accordionGroupDirective', function($delegate) {
var directive = $delegate[0];
directive.templateUrl = "views/parts/accordion-unit.html";
angular.extend(directive.scope, { index:'@' });
return $delegate;
});
}]);
然后,在我添加:index=“$index”
的模板中,我使用它键入{{index}}
,但始终未定义
有什么建议吗?谢谢确认这是Angular 1.3.x中的一个bug: 当前的解决方法是对指令使用
$$isolateBindings
,而不是.scope
。以下是代码的变通方法:
mainModule.config(['$provide',函数($provide){
$Provider.decorator('accordionGroupDirective',函数($delegate){
var指令=$delegate[0];
directive.templateUrl=“views/parts/accordion unit.html”;
指令。$$isolateBindings.index={
attrName:'索引',
模式:“@”,
可选:true
};
返回$delegate;
});
}]);
我也遇到了这个问题。decorator方法在最近的1.3.0-beta.13
中就开始使用,但在1.3.8中不再适用于我。你用的是什么版本的Angular?谢谢!成功了。我不明白为什么像angular这样一个伟大的框架仍然有这些bug和我发现的其他bug。干杯