Angular:RxStomp 监视、配置、激活方法
Angular: RxStomp Watch, Configure, Activate Method
在 Stomp 中我们使用了这些方法:
initUserEvents() {
this.stompService.startConnect().then(() => {
this.stompService.done('init');
this.stompService.subsribe('/channel/login', res => {
if (res.username !== this.username) {
this.newConnectedAccounts.push(res.username);
现在我正在使用 RxStomp,但我无法找出使用这些“替换”方法的正确方法:
initUserEvents() {
this.stompService.configure();
this.stompService.activate(){
this.stompService.watch('/channel/login', res => {
if (res.username !== this.username) {
this.newConnectedAccounts.push(res.username);
我得到的错误是:
TS2345:'(res: any) => void' 类型的参数不可分配给 'StompHeaders' 类型的参数。类型“(res: any) => void”中缺少索引签名。
查看 RxStomp 文档。它说:
The key difference is that it exposes operations as RxJS Observables. For example when a STOMP endpoint is subscribed it returns an Observable that will stream all received messages.
With exception of beforeConnect, functionality related to all callbacks in @stomp/stompjs Client is exposed as Observables/Subjects/BehaviorSubjects.
换句话说,您不会将回调传递给可用于获取消息的 watch
method. It returns an Observable
。
RxStomp API 希望您将 headers 传递给 watch
方法,而不是回调。这就是为什么它特别告诉你:
TS2345: Argument of type '(res: any) => void' is not assignable to parameter of type 'StompHeaders'.
在 Stomp 中我们使用了这些方法:
initUserEvents() {
this.stompService.startConnect().then(() => {
this.stompService.done('init');
this.stompService.subsribe('/channel/login', res => {
if (res.username !== this.username) {
this.newConnectedAccounts.push(res.username);
现在我正在使用 RxStomp,但我无法找出使用这些“替换”方法的正确方法:
initUserEvents() {
this.stompService.configure();
this.stompService.activate(){
this.stompService.watch('/channel/login', res => {
if (res.username !== this.username) {
this.newConnectedAccounts.push(res.username);
我得到的错误是: TS2345:'(res: any) => void' 类型的参数不可分配给 'StompHeaders' 类型的参数。类型“(res: any) => void”中缺少索引签名。
查看 RxStomp 文档。它说:
The key difference is that it exposes operations as RxJS Observables. For example when a STOMP endpoint is subscribed it returns an Observable that will stream all received messages.
With exception of beforeConnect, functionality related to all callbacks in @stomp/stompjs Client is exposed as Observables/Subjects/BehaviorSubjects.
换句话说,您不会将回调传递给可用于获取消息的 watch
method. It returns an Observable
。
RxStomp API 希望您将 headers 传递给 watch
方法,而不是回调。这就是为什么它特别告诉你:
TS2345: Argument of type '(res: any) => void' is not assignable to parameter of type 'StompHeaders'.