There are three methods I have seen to manage change detection in Angular2.
Observables
@Injectable() export class TodosService { todos$: Observable<Array<Todo>>; private _todosObserver: any; private _dataStore: { todos: Array<Todo> }; constructor(private _http: Http) { // Create Observable Stream to output our data this.todos$ = new Observable(observer => this._todosObserver = observer).share(); this._dataStore = { todos: [] }; } }
EventEmitter.
@Injectable() class NameService { name: any; nameChange: EventEmitter = new EventEmitter(); constructor() { this.name = "Jack"; } change(){ this.name = "Jane"; this.nameChange.emit(this.name); } }
Dot Rule
export interface Info { name:string; } @Injectable() class NameService { info: Info = { name : "Jack" }; change(){ this.info.name = "Jane"; } }
My question is, all three implementations can work when subscribing to watch changes in data. How do you decide when to use one instead of the other, and what are the drawbacks of each.