【发布时间】:2019-07-14 11:05:22
【问题描述】:
updateSubject() {
this.value = false;
this.howToUseObservables();
}
当我按下按钮时它会触发此功能,但行为主题没有按预期触发 .next 为什么?
value = true;
constructor() {
this.howToUseObservables().subscribe(ress => alert('in home ' + ress));
}
updateSubject() {
this.value = false;
this.howToUseObservables();
}
updateInOninle(subject: BehaviorSubject<any>) {
subject.next('from func online');
}
updateInOffline(subject: BehaviorSubject<any>) {
subject.next('from func offline');
}
howToUseObservables(): BehaviorSubject<any> {
const testSubjec: BehaviorSubject<any> = new BehaviorSubject('test');
if (this.value === true) {
this.updateInOninle(testSubjec);
} else {
this.updateInOffline(testSubjec);
}
return testSubjec;
}
【问题讨论】:
-
是什么让你说它不起作用?
标签: javascript angular ionic-framework rxjs behaviorsubject