我在CandidateManagementComponent中使用viewchild引用了一个名为CandidateEditorComponent的子组件。我在候选编辑器中有3种方法:editCandidate(),deleteCandidate(),newCandidate().... Delete工作正常.... new和edit都不行!他们给我这个错误:
无法读取未定义的属性“ editCandidate” 在CandidatesManagementComponent.editCandidate
我检查了ngif指令和属性,没有任何作用
这是我的候选人管理组件
newCandidate() {
this.editingCandidateName = null;
this.sourceCandidate = null;
this.editedCandidate = this.candidateEditor.newCandidate();//line giving error
this.editorModal.show();
}//not working
editCandidate(row: Candidate) {
this.editingCandidateName = { name: row.name };
this.sourceCandidate = row;
this.editedCandidate = this.candidateEditor.editCandidate(row);//line giving error
this.editorModal.show();
}//not working
deleteCandidate(row: Candidate) {
this.alertService.showDialog('Are you sure you want to delete the \"' + row.name + '\" candidate?', DialogType.confirm, () => this.deleteCandidateHelper(row));
}//this is working
这是我的候选人编辑器组件
this.isNewCandidate = true;
this.showValidationErrors = true;
this.editingCandidateName = null;
this.candidateEdit = new Candidate();
return this.candidateEdit;
}
editCandidate(candidate: Candidate) {
if (candidate) {
this.isNewCandidate = false;
this.showValidationErrors = true;
this.editingCandidateName = candidate.name;
this.candidateEdit = new Candidate();
Object.assign(this.candidateEdit, Candidate);
return this.candidateEdit;
} else {
return this.newCandidate();
}
}
这是我的html
<ng-template #actionsTemplate let-row="row" let-value="value" let-i="index">
<a *ngIf="canManageElections" class="btn btn-link btn-sm" href="javascript:;" (click)="editCandidate(row)"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> Edit </a>
<a *ngIf="!canManageElections" class="btn btn-link btn-sm" href="javascript:;" (click)="editCandidate(row)"><i class="fa fa-eye" aria-hidden="true"></i> Candidate Details</a>
{{canManageElections ? '|' : ''}}
<a *ngIf="canManageElections" class="btn btn-link btn-sm" href="javascript:;" (click)="deleteCandidate(row)"><i class="fa fa-trash-o" aria-hidden="true"></i> {{'roles.management.Delete' | translate}}</a>
</ng-template>
我希望按钮像删除按钮一样工作正常