Javascript 错误属性未定义,但存在未定义的检查
我尝试为参与者选择方框。因此,用户将能够向一个或多个参与者发送一些数据。在用户选择一些参与者后,用户将从anuglar材质重定向到模型对话框 所以我有这个:Javascript 错误属性未定义,但存在未定义的检查,javascript,angular,angular-material,observable,Javascript,Angular,Angular Material,Observable,我尝试为参与者选择方框。因此,用户将能够向一个或多个参与者发送一些数据。在用户选择一些参与者后,用户将从anuglar材质重定向到模型对话框 所以我有这个: export class EcheqSelectorComponent implements OnInit, OnDestroy { private subscriptions = new Subscription(); echeqs: EcheqFamilyInfo[] = []; allEcheqs: EcheqFamil
export class EcheqSelectorComponent implements OnInit, OnDestroy {
private subscriptions = new Subscription();
echeqs: EcheqFamilyInfo[] = [];
allEcheqs: EcheqFamilyInfo[] = [];
echeqFamily: EcheqFamilyInfo;
searchInput = '';
filtering = false;
participantInfo: ParticipantInfoDTO;
echeqsToSend: EcheqFamilyInfo[] = [];
echeqSubmissionBatchDTO: EcheqSubmissionBatchDTO;
participantIds$: Observable<string[]>;
patientId: string;
public participantIds: string[] = [];
public participantIdsFromRoute: string[] = [];
constructor(
private apiService: EcheqDefinitionService,
private dialog: MatDialogRef<EcheqSelectorComponent>,
public selectedParticipantService: SelectedParticipantsService,
private submissionService: EcheqSubmissionMedicalService,
private snackBar: MatSnackBar,
@Inject(MAT_DIALOG_DATA) public data: any,
public dialogRef: MatDialogRef<EcheqSelectorComponent>
) {
this.participantInfo = data.participant;
this.participantIdsFromRoute = this.data.participant.participantId ? [this.data.participant.participantId] : undefined;
}
ngOnInit() {
this.subscriptions.add(
this.apiService.listEcheqFamilies().subscribe(families => {
this.echeqs = families;
this.allEcheqs = families;
})
);
}
说:
EcheqSelectorComponent_Host.ngfactory.js? [sm]:1 ERROR TypeError: Cannot read property 'participantId' of undefined
at new EcheqSelectorComponent (echeq-selector.component.ts:50)
at createClass (core.js:18681)
at createDirectiveInstance (core.js:18550)
at createViewNodes (core.js:19776)
at createRootView (core.js:19690)
at callWithDebugContext (core.js:20722)
at Object.debugCreateRootView [as createRootView] (core.js:20208)
at ComponentFactory_.push../node_modules/@angular/core/fesm5/core.js.ComponentFactory_.create (core.js:18029)
at ComponentFactoryBoundToModule.push../node_modules/@angular/core/fesm5/core.js.ComponentFactoryBoundToModule.create (core.js:7812)
at ViewContainerRef_.push../node_modules/@angular/core/fesm5/core.js.ViewContainerRef_.createComponent (core.js:18140)
那么我要怎么做才能解决这个问题呢
谢谢问题在于
此.data.participant
未定义。因此,异常实际上是在验证检查期间发生的。从一致性的角度来看,您不应该在一个方法中将participant
属性设置为一个对象,而在另一个方法中只设置id。这可能就是造成混乱的原因。好的,谢谢你的answare。但是我必须改变什么呢?
this.participantIdsFromRoute = this.data.participant.participantId ? [this.data.participant.participantId] : undefined;
}
EcheqSelectorComponent_Host.ngfactory.js? [sm]:1 ERROR TypeError: Cannot read property 'participantId' of undefined
at new EcheqSelectorComponent (echeq-selector.component.ts:50)
at createClass (core.js:18681)
at createDirectiveInstance (core.js:18550)
at createViewNodes (core.js:19776)
at createRootView (core.js:19690)
at callWithDebugContext (core.js:20722)
at Object.debugCreateRootView [as createRootView] (core.js:20208)
at ComponentFactory_.push../node_modules/@angular/core/fesm5/core.js.ComponentFactory_.create (core.js:18029)
at ComponentFactoryBoundToModule.push../node_modules/@angular/core/fesm5/core.js.ComponentFactoryBoundToModule.create (core.js:7812)
at ViewContainerRef_.push../node_modules/@angular/core/fesm5/core.js.ViewContainerRef_.createComponent (core.js:18140)