Using $watch can solve the problem; it is not the most effective solution. You might want to change the way data is stored in the service.
The problem is that you are replacing the memory cell to which the taskList is bound, each time you assign a new value to it, when the area is stuck, indicating the old location. You can see it in this panel .
Take pictures of the heap using Chrome the first time you load the plunger, and after clicking the button, you will see that the memory location indicated by the scope is never updated, and the list points to another memory location.
You can easily fix this if your service holds an object that contains a variable that may change (something like data:{task:[], x:[], z:[]} ). In this case, the "data" should never change, but any of its members can be changed whenever you need. Then you pass this data variable to the scope and, until you redefine it, trying to assign the "data" to something else, whenever the field inside the data changes, the knowledge area will know about it and will be updated correctly.
This sheet shows the same example that runs using the fix proposed above. You do not need to use observers in this situation, and if it ever happens that something is not updated in the view, then you know that all you need to do is start the $apply to update the view.
Thus, you eliminate the need for observers who often compare variables for changes and ugly settings involved in cases where you need to watch a lot of variables. The only problem with this approach is that on your view (html) you will have โdataโ. prefixing everything where you used only the variable name.
Gabriel Piacenti Oct 02 '14 at 19:41 2014-10-02 19:41
source share