I created two directives:
directivesModule.directive("capital", function () {
return {
scope: {
capital: "@"
},
link: function () {}
}
})
directivesModule.directive("country", function () {
return {
scope: {
country: "@"
},
link: function () {}
}
})
Next, I use them in the same element:
<div country="Russia" capital="Moscow"></div>
As a result, I get an error: Error: [$compile:multidir] Multiple directives [capital, country] asking for new/isolated scope on: <div country="Russia" capital="Moscow">
How do I get the attribute values without scope?
These directives will not necessarily be used in conjunction.
I created two directives:
directivesModule.directive("capital", function () {
return {
scope: {
capital: "@"
},
link: function () {}
}
})
directivesModule.directive("country", function () {
return {
scope: {
country: "@"
},
link: function () {}
}
})
Next, I use them in the same element:
<div country="Russia" capital="Moscow"></div>
As a result, I get an error: Error: [$compile:multidir] Multiple directives [capital, country] asking for new/isolated scope on: <div country="Russia" capital="Moscow">
How do I get the attribute values without scope?
These directives will not necessarily be used in conjunction.
1 Answer
Reset to default 17According to your code, you don't need isolated scope to get attribute value. Just use this:
directivesModule.directive("capital", function ($parse) {
return {
link: function (scope, element, attrs) {
// get attrs value
attrs.capital
}
}
})
Attrs
(third) argument in your linking function and then$eval
or$parse
it against your scope in the function's body. – Kia Raad Commented Jan 12, 2014 at 10:33