demoApp is my module, very simple. I've followed a nice tutorial where it explains the custom directive creation, but something came out, the isolated scope thing to maintain the scopes isolated.
This is the angularJS code:
demoApp.directive("superhero", function() {
return {
restrict: 'E',
scope: {},
controller: function ($scope) {
$scope.abilities = [];
this.addStrength = function() {
$scope.abilities.push("strength");
}
this.addSpeed = function() {
$scope.abilities.push("speed");
}
this.addFlight = function() {
$scope.abilities.push("flight");
}
},
link: function (scope, element) {
element.addClass("button");
element.bind("mouseenter", function() {
console.log(scope.abilities);
})
}
}
});
demoApp.directive("strength", function() {
return {
require:"superhero", //require superhero controller
link: function (scope, element, attrs, superheroController) {
superheroController.addStrength();
}
}
});
demoApp.directive("speed", function() {
return {
require:"superhero",
link: function (scope, element, attrs, superheroController) {
superheroController.addSpeed();
}
}
});
demoApp.directive("flight", function() {
return {
require:"superhero",
link: function (scope, element, attrs, superheroController) {
superheroController.addFlight();
}
}
});
So then in the view I do this:
<superhero flight speed strength>Superman</superhero>
<superhero speed>Flash</superhero>
<superhero strength>Hulk</superhero>
Now, what happens if i want to access to the directive's controller scope of each of these childs? Imagine that i want to use the {{abilities}} binding with its respective properties in the view? Like so:
<superhero flight speed strength>Superman {{abilities}}</superhero>
How am i supposed to do it? Couldn't figure it out. Should i be using an isolated property? like :
scope: {
abilities: "&"
},
Thing is that, after reading and reading these isolated scopes, i couldn't understand yet the usage and differences.
UPDATED:
It looks like this is a "bug" from the AngularJS 1.2.3 because in the 1.1.1 version supplied by JSFiddle it works.
Maybe it's supported in a different way? How am i supposed to do this in the 1.2.3 version?