Javascript RXJS';主体内部功能

Javascript RXJS';主体内部功能,javascript,angular,ionic-framework,rxjs,subject-observer,Javascript,Angular,Ionic Framework,Rxjs,Subject Observer,请告诉我,我的代码不起作用,我需要帮助: this.howToUseObservables().subscribe(ress => alert('in app ' + ress)); 为什么testSubject.next('test')根本不开火? 谢谢 howToUseObservables():主题{ const testSubject:Subject=new Subject(); testSubject.next('test'); 返回测试主题; } this.howToUseO

请告诉我,我的代码不起作用,我需要帮助:

this.howToUseObservables().subscribe(ress => alert('in app ' + ress));
为什么
testSubject.next('test')根本不开火?
谢谢

howToUseObservables():主题{
const testSubject:Subject=new Subject();
testSubject.next('test');
返回测试主题;
}
this.howToUseObservables().subscribe(ress=>alert('in-app'+ress));

在订阅之前显示您正在调用的
next('test')
,因此它对以前的消息一无所知。您可以尝试
BehaviorSubject
您是对的,我使用了BehaviorSubject,效果很好,谢谢您的帮助:)在订阅之前,您正在呼叫
next('test')
,所以它不知道以前的消息。您可以尝试
BehaviorSubject
您是对的,我使用了BehaviorSubject,效果很好,谢谢您的帮助:)
howToUseObservables(): Subject<any> {
const testSubject: Subject<any> = new Subject();
testSubject.next('test');
return testSubject;
}

this.howToUseObservables().subscribe(ress => alert('in app ' +ress));