SekibOmazic / angular2-playground

MIT License
71 stars 7 forks source link

How does the by service way work? #4

Open cubika opened 9 years ago

cubika commented 9 years ago

For example, if FriendInput add an item to FriendsService, how does it notify FriendList that an item is added? I notice that no explicit call were made when new item added.

SekibOmazic commented 9 years ago

Right, there is no explicit call to notify FriendList that something has changed. There is also no $watch or something similar in FriendList that registers a callback handler.

In Angular 2 it all works automatically. Behind the scenes you have Zone.js that intercepts all asynch calls and triggers Angular's change detection.

The short (but good) description of what Zone.js does for Angular could be read here: https://github.com/angular/angular/blob/master/modules/angular2/docs/core/12_zones.md

Cheers ;-)