[英]AngularJs: multiple directives asking for isolated scope on
我创建了两个指令:
directivesModule.directive("capital", function () {
return {
scope: {
capital: "@"
},
link: function () {}
}
})
directivesModule.directive("country", function () {
return {
scope: {
country: "@"
},
link: function () {}
}
})
接下来,我在同一个元素中使用它们:
<div country="Russia" capital="Moscow"></div>
结果,我收到一个错误: Error: [$compile:multidir] Multiple directives [capital, country] asking for new/isolated scope on: <div country="Russia" capital="Moscow">
如何在没有范围的情况下获取属性值? 这些指令不一定要结合使用。
根据您的代码,您不需要隔离范围来获取属性值。 只要用这个:
directivesModule.directive("capital", function ($parse) {
return {
link: function (scope, element, attrs) {
// get attrs value
attrs.capital
}
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.