簡體   English   中英

如果Markdown編輯器在表單中留空,如何引發錯誤?

[英]How to throw an error if markdown editor left empty in the form?

我已經在我的角度HTML文件格式中使用了markdown編輯器,如下所示:

        <td-text-editor class="full-width" formControlName="description"></td-text-editor>

在表單中,如果我們將描述保留為空,則應該拋出錯誤。 有輸入嗎?

只需在formControl中添加所需的驗證器,即可在模板上顯示該formControl的錯誤

this.myform = new FormGroup({
'description': new FormControl(this.hero.power, Validators.required)
});

在您的模板上

<input id="name" class="form-control"
      formControlName="description" required >

<div *ngIf="description.invalid && (description.dirty || description.touched)"
    class="alert alert-danger">

  <div *ngIf="name.errors.required">
    Description is required.
  </div>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM