Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
7
rated 0 times [  14] [ 7]  / answers: 1 / hits: 20131  / 11 Years ago, sun, january 12, 2014, 12:00:00

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.


More From » angularjs

 Answers
6

According 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

}
}
})

[#73229] Friday, January 10, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
damiondenzelc

Total Points: 268
Total Questions: 116
Total Answers: 116

Location: North Korea
Member since Tue, Jun 16, 2020
4 Years ago
;