//this.testService.myBehaviourSubject.next("unwanted value"); } ngOnInit() { this.testService.setData(); this.getData(); } }Compiling application & starting dev server…angular-protected-rxjs-subject.stackblitz.io Console Clear on reload
https://stackblitz.com/edit/angular-if7hxd?file=src%2Fapp%2Fapp.component.ts Steps to reproduce 选择个第一个select What is expected? this.sf.value 里面的subjectId2的值为空 What is actually happening? 还是之前的值 EnvironmentInfo ng-alain 16.3.0 Browser chrome this.sf.getValue('subjectId2...
Subject 其实是观察者模式的实现,所以当观察者订阅 Subject 对象时,Subject 对象会把订阅者添加到观察者列表中,每当有 subject 对象接收到新值时,它就会遍历观察者列表,依次调用观察者内部的next()方法,把值一一送出。 Subject 之所以具有 Observable 中的所有方法,是因为 Subject 类继承了 Observable 类,在 Subject ...