AngularJS : how to reflect a variable change in one directive into another directive while using ng-repeat

穿精又带淫゛_ 提交于 2019-12-06 05:21:05

You have correctly guessed it! This is happening because of child scopes created by ng-repeat.

When you are creating a isolated scope with bar dependency the set operation on bar is setting the bar value on parent scope. In case of ng-repeat the parent scope is the ng-repeat scope and hence this behaviour.

Use a object instead of string to pass the string reference around and it will work. Check my plunkr http://plnkr.co/edit/JCQsIXzRv9FUNfJwhOAB?p=preview

Set bar variable as

$scope.data={};
$scope.data.bar ="original value";

User directive like

<directive2 bar="data.bar"></directive2>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!