cannot read property 'subscribe' of undefined in Angular

cannot read property 'subscribe' of undefined in Angular

You will get this error when you initialize the subject as below.

public tokenAcquired: Subject<any>;
and calling subscribe method over it as below.
this.appService.tokenAcquired.subscribe((token) => {
      this.getApps();
    })
Solution - To fix this error declare and initialize the subject as below.

public tokenAcquired: Subject<any> = new Subject<any>();

Thanks

Comments

Popular posts from this blog

npm ERR! Unable to authenticate, need: Bearer authorization_uri=https://login.windows.net/*********, Basic realm="https://pkgsprodcus1.pkgs.visualstudio.com/", TFS-Federated Fixed

ERR_CONNECTION_RESET - when you run application from visual studio over https

Azure - Failed to deploy web package to App Service. Internal Server Error (CODE: 500)- Fixed