Выражение изменилось после того, как было проверено значение - PullRequest
0 голосов
/ 01 мая 2020

Выражение изменилось после его проверки. Предыдущая value: 'ngIf: false'. Текущий value: 'ngIf: true'

<div class="editable comment-msg" *ngIf="c_editId == c.id"> 
 <form [formGroup]="editCommentForm" class="edit-form">
    <div class="edit-message">
      <textarea
        rows="3"
        type="text"
        class="form-control"
        formControlName="message"
        placeholder="Enter Comment "
        value="{{ c.message }}"
        maxlength="1024"
        #message>
      </textarea>
    <div class="custom-content-padding">
     <small class="form-text text-muted custom-display">
      <code>{{ message.value.length }}</code> of 1024 characters
     </small>
    <span *ngIf="message.value.length != 0" class="alert-success">
       <i class="fa fa-check" aria-hidden="true"></i> Your edit is good to go!
    </span>
  </form>
 <div>
 ...

this.commentForm = this.formBuilder.group({
    topicId: [this.topicId, Validators.required],
    message: [
      "",
      Validators.compose([Validators.required, Validators.maxLength(1024)])
    ]
  });

  this.editCommentForm = this.formBuilder.group({
    message: [
      "",
      Validators.compose([Validators.required, Validators.maxLength(1024)])
    ]
  });
  this.getCommentsCommentPage();
});



  editCommentToggle(c: Comment) {

   this.attachments2 = [];
   var id = String(c.id)
   document.getElementById(id).style.display = "none";

   this.setTitleEdit = true;
   this.c_editId = c.id;
   this.comment = c;
   this.deleteFilesCheckboxes.length = 0;

   if (this.filepath[c.id] != null) {
    for (let file of this.filepath[c.id]) {
     this.deleteFilesCheckboxes.push(new FileToCheckbox(false, file));
     }
   }
}

При нажатии кнопки редактирования над комментарием оператор *ngIf в строке 1 становится истинным. Комментарий при редактировании всегда начинается с хотя бы одного символа.

Вторая проблема *ngIf. Вышеуказанная ошибка отображается, но код работает нормально. Я видел другие сообщения с похожими названиями ошибок, но не могу применить ошибку или исправить ее.

1 Ответ

0 голосов
/ 01 мая 2020

Я предполагаю, что у вашего setTitleEdit есть некоторые проблемы с проверкой.

Чтобы исправить это, добавьте ChangeDetectorRef в ваш конструктор

constructor(private changeRef: ChangeDetectorRef)

И затем вызовите detectChanges в setTitleEdit

editCommentToggle(c: Comment) {

   this.attachments2 = [];
   var id = String(c.id)
   document.getElementById(id).style.display = "none";

   this.setTitleEdit = true;
   this.changeRef.detectChanges();
   this.c_editId = c.id;
   this.comment = c;
   this.deleteFilesCheckboxes.length = 0;

   if (this.filepath[c.id] != null) {
    for (let file of this.filepath[c.id]) {
     this.deleteFilesCheckboxes.push(new FileToCheckbox(false, file));
     }
   }
}
...