خرید بک لینک

Vote count: 0

The main point of this post is that I want to avoid using $scope.$watch as it is taught to cause a performance decrease.

So imagine having one shared view partial/template, call it "mypage" with two different directives, call them "directive1" and "directive2", in it that share a data model, lets call it "awesomeData"

Maybe it looks something like this:

<div class="mypage-root">
   <directive1 shared-data="awesomeData"></directive1>
   <directive2 shared-data="awesomeData"></directive2>
</div>

Now obviously when "awesomeData" changes in either directive or the root view, the data changes in the other parts too (assuming it is two-way bound).

But what if i want something else to happen in directive2 when directive1 has updated the data model, like calling a function in directive2?

I could use a watcher but as mentioned, that is a performance decrease.

What other approaches are there and what is the "true" angular way to do this?

asked 1 min ago

- - , .

برچسب: نویسنده: استخدام کار تاريخ: چهارشنبه 5 اسفند 1394 ساعت: 2:45

صفحه بندی