I would like to see an object / array that can be edited by a service or controller routine. I thought Observable could observe an object / array.
My implementation does not respond to element changes:
private data : Observable<Array<any>>; private dataObserver: Observer<Array<any>>; private sub : Subscription; private items: <Array<any>>; ngOnInit() { this.items = itemService.getItems(); this.data = new Observable<Array<any>>(observer =>{ this.dataObserver = observer; }); this.data.subscribe( x => console.log('onNext: %s', x), e => console.log('onError: %s', e), () => console.log('onCompleted') ); this.dataObserver.next(this.items); } private start(){ //change values of the array in an interval let loop = Observable.interval(250) let i=0; self.sub = loop.subscribe(() => { if(self.items[0]){ self.items[0].id= i; if(i<100) i++; else i=1; } }) }
The Obsalbes hint does not respond to changes to the array of elements. This only works on his next method. On the other hand, it is too cumbersome for a simple observation method.
What angular -2 offers for viewing changes like $ scope. did $ watch do in angular -1?
angular typescript
marcel
source share