Angular2 injected Router is undefined

情到浓时终转凉″ 提交于 2019-12-02 01:43:10

You can use the arrow function to make sure you can still have a reference to this and it is LoginComponent instance:

....subscribe((data) => this.loginCallback(data));

Another option is use bind method like:

....subscribe(this.loginCallback.bind(this));

or in contructor:

this.loginCallback = this.loginCallback.bind(this);

One more option is using arrow function within your loginCallback:

private loginCallback = (data: any) => {
  ...
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!