我试图使一个对话框弹出每当我得到一个错误从myerrorhandler我可以看到console.error(this.explanation)
调用,但不是this.dialogbox.openDialogTEST();
这是我的错误消息。
错误类型错误:无法读取未定义的属性'openDialogTEST'
奇怪的是,如果我用按钮调用它,一切都很好。这是我的课程:
usertable.component.ts
connect(): Observable<Installation[]> {
return this.authservice.GetInstallation();
}
auth.service.ts
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)
)
}
myerrorHandle.ts
handleError(errorResponse: HttpErrorResponse) {
switch (errorResponse.status) {
case 401: {
console.error(errorResponse.url, errorResponse.status, errorResponse.statusText)
this.explanation = "The request has not been applied because it lacks valid authentication credentials for the target resource."
console.error(this.explanation)
this.dialogbox.openDialogTEST();
break;
}
对话框.component.ts
openDialogTEST(): void {
const dialogRef = this.dialog.open(DialogOverviewExampleDialog, {
});
dialogRef.afterClosed().subscribe(result => {
console.log("after close")
});
}
完整错误消息:
错误类型错误:无法读取未定义的属性'openDialogTEST'node_modules./src/app/_esm5[作为选择器](node_modules)在_esm5./_esm5/rxjs/_error/内部/运营商/_error(node_modules)在_esm5./Subscriber.js.Subscriber.error/rxjs/Subscriber.js:60/内部/node_modulesInnerSubscriber.push.MergeMapSubscriber.push.(_esm5)在_error./OuterSubscriber.js.OuterSubscriber.notifyError/rxjs/OuterSubscriber.js:13/内部/node_modules(_esm5)在node_modules./Subscriber.js.Subscriber./rxjs/InnerSubscriber.js.InnerSubscriber./内部/_esm5InnerSubscriber.js:18(_error)在node_modules./Subscriber.js.Subscriber.error/rxjs/Subscriber.js:60/内部/_esm5(node_modules)在_esm5./MapSubscriber.push./rxjs/Subscriber.js.Subscriber./内部/node_modulesSubscriber.js:80(Subscriber.js:80)在FilterSubscriber.push../MapSubscriber.push./rxjs/Subscriber.js.Subscriber.error/内部/myerrorHandle.ts:29(CatchSubscriber.push.)在catchError.js.CatchSubscriber.error./Subscriber.js:60/rxjs/FilterSubscriber.push./内部/catchError.js:33(MergeMapSubscriber.push.)在Subscriber.js.Subscriber../Subscriber.js.Subscriber./rxjs/CatchSubscriber.push./内部/Subscriber.js:80myerrorHandle.ts.myerrorHandle.handleError(MergeMapSubscriber.push.)
使用服务来处理这样的对话:
有关更多详细信息,请参考演示
演示
dailogbox.service。ts:
import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { MatDialogRef, MatDialog, MatDialogConfig } from '@angular/material';
import { DialogOverviewExampleDialog } from './dialog-overview-example'
@Injectable()
export class DialogboxopenService {
constructor(
private commonModel: MatDialog
) { }
public openmodel(title: string): Observable<boolean> {
let ModelRef: MatDialogRef<DialogOverviewExampleDialog>;
ModelRef = this.commonModel.open(DialogOverviewExampleDialog,
{ width: '50%' }
);
ModelRef.componentInstance.data = title;
return ModelRef.afterClosed();
}
}
auth.service.ts:
import { Injectable } from '@angular/core';
import { HttpClient, HttpErrorResponse } from '@angular/common/http';
import { Observable } from 'rxjs';
import { DialogboxopenService } from './dialogboxopen.service';
@Injectable()
export class AuthService {
constructor(private dailogbox: DialogboxopenService, private http: HttpClient) { }
signIn() {
this.http.get('https://urlnotfound/sas').subscribe(response => {
console.log(response)
}, (error: HttpErrorResponse) => {
this.handleError(error);
})
}
handleError(errorResponse: HttpErrorResponse) {
switch (errorResponse.status) {
case 0:
let m1 = `The request has not been applied because url not found status code ${errorResponse.status}`
this.dailogbox.openmodel(m1);
break;
case 500:
let m2 = `The request has not been applied because Internal Server Error Status Code : ${errorResponse.status} `
this.dailogbox.openmodel(m2);
break;
}
}
}
我的代码: 错误: 未处理PromisejectionWarning:TypeError:无法读取未定义的未处理PromisejectionWarning:未处理的promise拒绝的属性“forEach”。此错误源于在没有catch块的情况下抛出异步函数的内部,或者拒绝使用未处理的promise。catch()。(拒绝id:1)(节点:7188)[DEP0018]弃用警告:未处理的promise
我想在我的角度项目中添加钢系列。我有createad html-compass组件,但我收到了这个错误: _services错误类型错误:无法读取未定义的属性(读取主题)在ProjectService…/app/Subject.js:53/_next(node_modules)在_esm5__tryOrUnsub[EventEmitter.push.](node_modules)在_esm5…/c
在我的错误处理程序中,当我遇到错误时,我试图导航到另一个页面。 我尝试获取项目列表,如果失败,我想导航到“/error401”。我一直试图这样做: UserTablecomponent: 这个电话可能有点奇怪。它所做的是调用其余的,看看我有什么基于令牌的ID。然后在下一次调用中使用该ID 授权服务 迈勒手 这是我想导航到“/error401”的地方,但是 错误错误类型错误:无法读取未定义的属性“导
尝试使用< code>getAuth请求来存储令牌。请求不调用API并抛出错误。 TypeError:无法在HttpHeaders.push处读取undefined的属性(读取“length”)../node _ modules/@ angular/common/Fe sm5/http . js . http headers . apply update(http . js:199)at http
我正在选择area_enninFantry的所有子div,并循环调整某些子div的文本。cardArray是一个全局常量,myId在父函数中定义。 未捕获的TypeError:无法读取未定义的属性(读取“getAttribute”) 我在这篇文章中读到,这可能是因为字段/元素的内容可能是DOM元素,我应该用$()包装它们,所以我确实这样做了——将两个变量都更改为$(元素)[a]. attr(“标题
我遇到了一个有趣的问题,这使我感到困惑。我正在执行一个正确返回数据的Sharepoint RestAPI调用,当我在数据上运行for循环时,它生成html,但仍然抛出我用作标题的错误。代码如下。如果我记录每个循环,它将返回值。HTML也可以很好地工作。问题是错误仍然会出现。