How to keep listening for changes in the value of a field in Anguar4.

some scenarios are encountered during the development process using the angular4 framework.
for example: there is a global drop-down list in the common component, and every time the value of the drop-down list changes, all activated subcomponents change accordingly. There is a $watch instruction in ng1, but no similar method was found in ng4.
currently uses a lifecycle Docheck (), that consumes a lot of performance, and there are some unexpected problems. I would like to ask if there is a better monitoring method.


combined with Rxjs , the value of the drop-down list is placed in the common service as a BehaviorSubject , and the async pipe parsing value is directly used on the subcomponent template.
example (service): of common components


<del></del><br>

@Injectable()
class CustomService{
    public customAttr:number=0;
    constructor(){
        setInterval(()=>this.customAttr=Math.random(),1000);
    }
}

dependency injection of this service in the component

constructor(public customService:CustomService){}

then in the html template, you can directly use the attribute values in the service to render

.
<div>{{customService.customAttr}}</div>
Menu