Angular 2 watch component property for changes without @Input or @Output -
in angular 1.x use .$watch watch wanted, in angular 2 have ngonchanges cool , performant watches input , output decorators. time time need watch local properties can emit event when change. remember seeing article explaining how can explicitly tell angular 2 watch single property life of me can't find article anymore , every search tells me use input/output decorators onchanges. how can create watcher @viewchild or other local properties?
for example have ngform, when it's validation state changes valid invalid or vise versa want emit state component can react. since ngform @viewchild , not @input or @output ngonchanges doesn't detect change.
the equivalent custom angular 1 $watch()
in angular 2 implement lifecycle hook ngdocheck()
, perform own checking. lifecycle hooks dev guide has an example.
note ngdocheck()
method called every time change detection runs (just angular 1 watch), sure implemented efficiently possible.
try use rxjs (an observable, subject, etc.) instead, if possible, more efficient. used able subscribe ngform's controlgroup notified of changes, don't know if still available.
Comments
Post a Comment