Search code examples
typescriptsignalrangular9angular-upgrade

ng2-signalR throwing error after angular upgrade to 9


Recently upgraded to angular 9 able to run but got the below error in certain components where ng2-signalR is used. enter image description here

enter image description here

Here is the component code

import { SignalR, IConnectionOptions } from 'ng2-signalr';

constructor(private _signalR: SignalR)

ngOninit(){
 let o: IConnectionOptions;
    let conx = this._signalR.createConnection();
    conx.status.subscribe((s) => {if(s.name=='disconnected') {conx.start()}});
    conx.start().then((c) => {
      let listener = c.listenFor('getChanges');
      listener.subscribe((data) => {
        if (data == 'UpdateSitRep') {
         //do something;
        }
      });
    });
}

Here is the app.module.ts

import { SignalRModule, SignalRConfiguration } from "ng2-signalr";

export function createConfig(): SignalRConfiguration {
  const c = new SignalRConfiguration();
  c.hubName = 'NotifyHub';
  c.qs = { user: '' };
  c.url = `${environment.apiUrl}/signalr`;
  c.logging = true;
  c.executeEventsInZone = true; // optional, default is true
  c.executeErrorsInZone = false; // optional, default is false
  c.executeStatusChangeInZone = true; // optional, default is true
  return c;
}

version of ng2-signalr "ng2-signalr": "^6.1.0"


Solution

  • There is a fork called "@henkkelder/ng2-signalr" that can be used as ng2-signalr support has stopped after angular 9 .