多指令资源争用'当创建自定义指令和使用ui引导时
Error 'Multiple Directive Resource Contention' when creating custom directive and using UI-bootstrap
我正在尝试创建一个指令,该指令具有输入评级,并根据此输入在DOM中绘制星星。
但是,当我尝试以下操作时:
.directive('stars', function (Utils) {
return {
restrict: 'AE', //E = element, A = attribute, C = class, M = comment
transclude: true,
template: "{{starsObj}}",
link: function (scope, element, attrs) {
scope.starsObj = Utils.returnStars(attrs.rating)
}
}
})
,其中Utils.returnStars(attrs.rating)
返回一个数组(我想稍后使用)。
…我得到以下错误:
多指令资源争用
https://docs.angularjs.org/error/编译/multidir美元? p0 = rating& p1 = % 20(模块:% 20 ui.bootstrap.rating), p2 = stars& p3 = % 20(模块:% 20 noodl.controllers-product)和p4 = template& p5 3 = % % 20 cspan ng-mouseleave % 3 d % 22重置()% 20评级% 3 d % 225% 22% 22% 3 e
从我的项目中删除ui-bootstrap解决了这个问题,但我最终确实需要ui-bootstrap。
怎么回事?
您不需要添加'scope '。'前缀到你的变量从指令范围,所以你应该改变你的指令的template
属性为:
return {
restrict: 'AE', //E = element, A = attribute, C = class, M = comment
transclude: true,
template: "{{starsObj}}", //You don't need 'scope.' prefix.
link: function (scope, element, attrs) {
scope.starsObj = Utils.returnStars(attrs.rating)
}
}
活塞的演示。
UPD:但是我看到控制台的错误与ui-bootstrap
有关。你能提供代码更多的代码,你在哪里使用它?
UPD2:这里的问题是ui.bootstrap
有他自己的评级指令。所以,要解决这个问题,你可以把stars
指令的rating
属性重命名为其他东西。我更新了我的活塞
相关文章:
- Angular JS/UI Router:为给定状态禁用指令
- Angular UI Select2指令搜索功能不起作用
- 使用 Angular 和 UI-bootstrap 对模态事件绑定无法工作的指令
- 获取 Angular UI-Calendar 上的所有事件(Arshaw 完整日历的指令)
- angularjs+ui.router:指令控制器和链接函数之间的不同行为
- 在ui路由器中以Webpack块的形式懒惰地加载Angular指令
- 用于单元测试的模拟Angular引导程序ui指令
- AngularJS ui路由器:ui sref和指令
- 角度指令的父作用域未更新UI
- ng使用UI引导指令绑定html
- UI-掩码和 $parser/$formatters 在同一个指令中不起作用
- UI Bootstrap for Angular 带有 'collapse' 指令,不调用 expand
- 如何通过角度 ui-grid 中来自$scope的数据动态设置指令
- 如何使用 AngularJS ui-date 指令格式化初始日期值
- 语义 UI 弹出窗口在 angularjs 指令中不起作用
- 角度 ui 路由器的问题 - 我无法将过滤器应用于指令中的重复
- 将 Angular.js ui-bootstrap 或 ui-select 指令包装在自己的指令中
- UI 引导程序自定义指令控制器不是一个函数
- 如何使用角度模块“ui-route”在指令中查找模板URL,而不会在MVC .NET上出现错误
- angular ui指令未绑定到使用$resource加载的数据