Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
380 views
in Technique[技术] by (71.8m points)

typescript - How to get the local reference value from a template driven form tag dyanamically in angular?

Below is my template driven form.

I want to get the local reference name (#{{obj.sample_name}}) in the *ngIf to show error message. how to achieve this?

<form class="theme-form" name="sample" #sample="ngForm">
  <div *ngFor="let obj of items">

    <input type="text" 
           class="form-control" 
           [(ngModel)]="obj.sampleValue" 
           name={{obj.sample_name}} 
           #{{obj.sample_name}}="ngModel" 
           [range]="[1, 12]">

    <p *ngIf="{{obj.sample_name}}.errors?.range">
      error message
    </p> 
    <!-- I want the name of the dyanamic form reference here to show errors -->

  </div>
</form>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...