There is a functionality where we use nested angular directives. I am adding a simplified example where the behavior can be observed.
Here is the HTML:
<body ng-app="myapp">
<div>
This is the first directive
<first-directive my-val="9">
</first-directive>
</div>
</body>
And the JavaScript:
var app = angular.module("myapp",[]);
app.directive("firstDirective",function(){
return {
template:'<second-directive val-new={{myVal}}></second-directive>',
scope:{
myVal:'@'
},
//transclude:true,
link: {
pre:function(scope,elem,attr){
scope.myVal=scope.myVal+"1";
}
}
}
});
app.directive("secondDirective",function(){
return{
scope:{
valNew:'@'
},
link:{
pre:function(scope,elem,attr){
console.log(scope.valNew);
}
}
}
});
In the console I get the result of the update made in the pre method, but in the html I get the old value.
Console prints: "91" The html dom contains:
<second-directive val-new="9" class="ng-isolate-scope"></second-directive>>
Please help me understand why this difference is observed and how to make these two places consistent
EDIT
I am just looking for a way to make the scope variables in the second directive react to the changes made in the linked variables of the first directive's scope. So in some other place when the myVal
changes, I am looking to make the second directive react to the changes.