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>
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e448c7-44ac1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e448c7-44ac1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?