How to use SignalR with Angular 2?

后端 未结 4 845
轮回少年
轮回少年 2021-02-06 09:12

How to use SignalR with Angular 2?

How to manually run change detection when receiving data from SignalR?

4条回答
  •  庸人自扰
    2021-02-06 09:53

    You didn't specified wich syntax you're using to develop your Angular 2 app.

    I will assume you're using typescript.

    One approach is use Definitely Typed files.

    1 - You'll need to download a Definitely Typed JQuery:

    https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/jquery/jquery.d.ts

    2 - After this, download a Definitely typed SignalR:

    https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/signalr/signalr.d.ts

    3 - Add the JQuery refence in your Component:

    /// 
    

    4 - Now, you can call SignalR methods with intelissense. But you will need to use the Late Binding approach:

    var connection = $.hubConnection(); var proxy = connection.createHubProxy(proxy.on("newOrder", (order) => console.log(order)); connection.start();

提交回复
热议问题