小编Ash*_*hok的帖子

内部jQuery函数我可以调用Angular 5函数

我正在尝试在jQuery函数内调用onPaymentStatus()函数。但是我无法使用“这个”范围

this.braintree.client.create({
  authorization: 'client_token'},
  (err, client) => {
      client.request({
        endpoint: 'payment_methods/credit_cards',
        method: 'post',
        data: data
      }, function (requestErr, response) {

       if (requestErr) { throw new Error(requestErr); }
       console.log('Got nonce:', response.creditCards[0].nonce);
       this.onPaymentStatus(response.creditCards[0].nonce); //
    });
});

onPaymentStatus (nonce) {
  console.log(nonce);
}
Run Code Online (Sandbox Code Playgroud)

我收到错误ERROR TypeError:无法读取null的属性'onPaymentStatus'

angular

5
推荐指数
1
解决办法
1607
查看次数

如何在角度5的一定时间后防止websocket关闭?

我使用'rxjs-websockets'来连接websockets.但在一定时间(约2分钟)后,连接关闭.在手动关闭之前,如何保持连接.

这是我使用的代码片段

constructor(private socketService: WebSocketService) {}

this.socketService.connect('/endpoint');
this.socketSubscription = this.socketService.messages
      .subscribe(result => {            
            // perform operation
    });
Run Code Online (Sandbox Code Playgroud)

这是WebSocketService

import {Injectable} from '@angular/core';
import {QueueingSubject} from 'queueing-subject';
import {Observable} from 'rxjs/Observable';
import websocketConnect from 'rxjs-websockets';
import 'rxjs/add/operator/share';
import 'rxjs/add/operator/retryWhen';
import 'rxjs/add/operator/delay';

@Injectable()
export class WebSocketService {
  private inputStream: QueueingSubject<string>;
  public messages: Observable<string>;

  constructor() {    
  }

  public connect(socketUrl) {
      this.messages = websocketConnect(
        socketUrl,
        this.inputStream = new QueueingSubject<string>()
      ).messages.retryWhen(errors => errors.delay(1000))
        .map(message => JSON.parse(message))
        .share();
  }

  public send(message: string): void {
    this.inputStream.next(message);
  } …
Run Code Online (Sandbox Code Playgroud)

websocket rxjs angular5

4
推荐指数
1
解决办法
683
查看次数

如何根据第一个组件收到的websocket事件更新第二个组件中的内容?

我有一个在组件A中编写的websocket逻辑,如下所示.

    this.socketService.connect('/socket_url');
    this.statusSubscription = this.socketService.messages
      .subscribe(result => {
        if (result !== 'pong') {
            // update Component B with the response obtained
        }
    });
Run Code Online (Sandbox Code Playgroud)

我想知道每当我在旅途中收到websocket活动时如何更新组件B.

websocket typescript angular angular5

3
推荐指数
1
解决办法
67
查看次数

标签 统计

angular ×2

angular5 ×2

websocket ×2

rxjs ×1

typescript ×1