I have a nontrivial Angular SPA that uses ui-router to manage multiple views, many of which are visible at the same time. I need the models to be visible through the controllers, so I have written services that allow me to have controllers to pull out fresh copies of the model data that have been updated.
I apologize in advance for the length of the question, but I will formulate the problem, and then indicate what I did to solve the problems. I am sure that other users of the Angular community have encountered a problem.
I believe that my problem is not understanding the life cycle of the controllers / views, because I get the behavior when the controller correctly initializes the first time I go there, but then it seems it never starts again, even when I go to it, using something like $state.go("state name").
In one view (a far-fetched example), I show a summary of customer information, and in another view, I allow the user to update this client with a more detailed profile. I want the user to edit, say, the name of the client in a detailed view, and the summary view will automatically recognize the change and display it.
I have a fiddle that shows 3 views and a simple password change service. The stream is as follows:
- You can see that each view is initialized and displays the initial password received from the service. All views are synchronized with the DataService.
- The middle view allows you to enter a new password and change the one that is stored in the service. Console logging confirms that the service takes the new password just as you expected.
- (odd behavior # 1) When the DataService gets a new password, I expect the other 2 views (top and bottom) to display a new one. They donβt ... they still display the initial password.
- ,
state $state.go("state name") ( ), . (. β 5). , , . , , DataService . - ( # 2) , , , ( 4) . 3 , , , Angular.
:
- - , , , ui-router , . , , , , 30 , 100 REST. , , . , 0.2.8.
- , . . ,
$rootScope.emit() $scope.$onRootScope('event name'), . , , . Angular events . $watch DataService? , $watch es .- , bacon.js ( ), ,
$digest agedon. , Angular, . - -,
.service , , , $watch es $digest, Angular? - , OO , , 0. *.
... !