簡體   English   中英

是否可以在Angular 2的模板HTML中引用此表單?

[英]Is it possible to refer to this form in template HTML in Angular 2?

我有一個如下按鈕。

<button type="button" class="button-next btn btn-primary" nextStep>Next
  <i class="icon-arrow-right14 position-right"></i>
</button>

它在帶有formGroupName="company"的嵌套表單組下。 如果公司無效,我想禁用按鈕的點擊事件。 另外,我想為formGroupName="company"中的所有字段設置臟內容,以便觸發驗證程序並顯示錯誤消息。

我可以在按鈕的(click)事件中執行此操作,但是我試圖找到一種最佳方法來執行此操作,例如以this formGroupName作為輸入並執行操作的函數,而不是我顯式地傳遞formGroupName 我在頁面中有多個formGroupName。

我不想使用按鈕的disabled屬性,因為我想在單擊按鈕時觸發驗證。

上面需要做的最好的方法是什么?

在組件集中,設置為boolean類型的標志。

export class ComponentName{
    showHideFlag:boolean;

}

如果公司無效,則將標志設置為false,否則將其設置為true。 在按鈕的HTML中,根據需要使用ngIf顯示或隱藏此按鈕

 <button type="button" *ngIf="showHideFlag" class="button-next btn btn-primary" nextStep>Next
  <i class="icon-arrow-right14 position-right"></i>
 </button>

暫無
暫無

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

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