0
サービスからコンポーネントに更新された値を取得する方法を教えてください。以下では、ConnectValueからMasterComponentにshowValuesを取得しようとしています。角2サービスからコンポーネントに最新の更新値を取得する方法
export class MasterComponent{
public showValue:string;
constructor(public connectService: ConnectService, public _router: Router){
if(localStorage.getItem("clientStatus")=='connected'){
this.showValue = this.connectService.showValues;
console.log("MasterComponent",this.showValue);
}
}
以下のサービスから、コンポーネントを更新したいです。
export class ConnectService{
public showValues: string;
constructor(){
}
recvNotify(m) {
//getting value
buttonName = innervalue;
console.log("ELSEinnervalue",buttonName);
switch (buttonName) {
case "0x01010000":
console.log('showValue==1');
this.showValues = "1";
break;
case "0x01020000":
console.log('showValue==2');
this.showValues = "2";
break;
default:
console.log('showValue==3');
this.showValues = "3";
}
}
}
に私はちょうど私のサービスからの変数を更新しようとしています
rxjs
からSubject
を使用しています。これを行う簡単な方法はありますか? – NMNBこれはEventEmitterで通知者として使用できるのは2つの基本的な方法です。もう1つはSubjectを使用してObservableです –