Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Looking for analog of RxJs ofObjectChanges method in Angular 2

Tags:

angular

rxjs

I want to create class property decorator which will look for all changes of this property and do some stuff. How can i do that?

In RxJs i found ofObjectChanges method https://github.com/Reactive-Extensions/RxJS/blob/master/doc/api/core/operators/ofobjectchanges.md

but looks like that method does not exist in angular2 RxJs version.

That method must trigger on changes of object, for example with Array.push();

like image 243
Качалов Тимофей Avatar asked Feb 17 '16 15:02

Качалов Тимофей


1 Answers

You're right, there's no (yet?) implementation of that method in RxJs 5 beta currently used in Angular 2: Migrating from RxJs 4 to 5. But it is not actually clear if you really need it.

If you use typescript then you can see about writing decorators here. Also, you can look into angular's sources, kind of starting point is modules/@angular/core/src/metadata/directives.ts. You can see how angular team implemented @Input() decorator and figure out how to do it in your case which sounds pretty similar to me.

like image 87
Alexander Leonov Avatar answered Oct 02 '22 21:10

Alexander Leonov