Node.js 角度6错误类型错误:无法读取未定义的属性“导航”
在我的errorhandler中,当我遇到错误时,我试图导航到另一个页面 我尝试获取项目列表,如果失败,我想导航到。/error401。我一直试图这样做: UserTablecomponent: 这是我想导航到的。/error401,但是获取 错误类型错误:无法读取未定义的属性“navigate” 这是完整的错误日志: 错误类型错误:无法读取未定义的属性“navigate” 在CatchSubscriber.push../src/app/myerrorHandle.ts.myerrorHandle.handleError [作为选择器]myerrorHandle.ts:18 在CatchSubscriber.push../node_modules/rxjs/_esm5/internal/operators/catchError.js.CatchSubscriber.error catchError.js:33 在MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.\u错误 订户.js:80 在MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error 订户.js:60 在MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.\u错误 订户.js:80 在MapSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error 订户.js:60 在FilterSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.\u错误 订户.js:80 在FilterSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.error 订户.js:60 在MergeMapSubscriber.push../node_modules/rxjs/_esm5/internal/OuterSubscriber.js.OuterSubscriber.notifyError OuterSubscriber.js:13 在InnerSubscriber.push../node_modules/rxjs/_esm5/internal/InnerSubscriber.js.InnerSubscriber.\u错误InnerSubscriber.js:18Node.js 角度6错误类型错误:无法读取未定义的属性“导航”,node.js,angular,typescript,rxjs,Node.js,Angular,Typescript,Rxjs,在我的errorhandler中,当我遇到错误时,我试图导航到另一个页面 我尝试获取项目列表,如果失败,我想导航到。/error401。我一直试图这样做: UserTablecomponent: 这是我想导航到的。/error401,但是获取 错误类型错误:无法读取未定义的属性“navigate” 这是完整的错误日志: 错误类型错误:无法读取未定义的属性“navigate” 在CatchSubscriber.push../src/app/myerrorHandle.ts.myerrorHandl
您需要在代码中使用arrow函数才能使用该类上下文
您需要在代码中使用arrow函数才能使用该类上下文 正如@user184994所说: 将catchError更改为catchErrorerr=> 此.myerrorhandle.HandleErrorr不带箭头 函数的上下文丢失 正如@user184994所说: 将catchError更改为catchErrorerr=> 此.myerrorhandle.HandleErrorr不带箭头 函数的上下文丢失 将catchError更改为catchErrorerr=>this.myerrorhandle.handleerror否则无箭头函数此上下文丢失将catchError更改为catchErrorerr=>this.myerrorhandle.handleerror否则无箭头函数此上下文丢失
export class UserDataSource extends DataSource<any>{
constructor(private authservice: AuthService) {
super();
}
connect(): any {
return this.authservice.GetInstallation();
}
disconnect() { }
}
GetServiceProviderId(): Observable<Info> {
return this.http.get<Info>(this.rooturl + 'info', { headers: this.reqHeader });
}
GetInstallation(): Observable<Installation[]> {
return this.GetServiceProviderId().pipe(
flatMap(info => {
return this.http.get<Installation[]>
(this.rooturl +
"installation/?serviceproviderid=" +
info.ServiceProviderId,
{ headers: this.reqHeader })
}
), catchError(this.myerrorhandle.handleError))
}
}
@Injectable({
providedIn: 'root'
})
export class myerrorHandle {
constructor(public router: Router) { }
handleError(errorResponse: HttpErrorResponse) {
switch (errorResponse.status) {
case 401: {
this.router.navigate(["./error401"])
break;
}
default: {
console.log("todo");
break;
}
}
return throwError('an error was thrown');
}
}
catchError(() => this.myerrorhandle.handleError));