Не удается прочитать свойство 'editCandidate' из неопределенного в CandidatesManagementComponent.editCandidate при использовании ViewChild - PullRequest
0 голосов
/ 07 октября 2019

Я ссылаюсь на дочерний компонент под названием CandidateEditorComponent, используя viewchild в моем CandidateManagementComponent. У меня есть 3 метода в редакторе кандидатов: editCandidate (), deleteCandidate (), newCandidate () .... Удалить работает нормально .... новые и редактировать нет! Они дают мне эту ошибку:

Невозможно прочитать свойство 'editCandidate' undefined в 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>

Я ожидаю кнопкидолжны работать нормально, как удалить

...