0

I am trying to generate form dynamically . I am trying to set element reference to ngModel dynamically but it is not working .

 #{{item.name}}="ngModel"

.Here is the code

  <input type={{item.type}} class={{item.className}} placeholder="{{item.placeholder}}"
  [(ngModel)]="item.value" name='{{item.name}}' #{{item.name}}="ngModel"
  [ngClass]="{ 'is-invalid': f.submitted && item.value==''}" [required]="item.required">

Json

{
className: "form-control"
icon: "fa-font"
label: "TextBox"
layout: "row"
layoutList: (2) [{…}, {…}]
name: "textq6es58"
placeholder: "Enter your name"
required: true
toggle: true
type: "text"
}

Is there any way to set Dynamic element reference in angular template driven forms?

1
  • it's not neccesary. use simply #item I suppose your'e using in a *ngFor. Angular "create" a different template reference (really the reason is that Angular take account the scope, and the scope is different)
    – Eliseo
    Commented May 28, 2020 at 15:16

1 Answer 1

0

You can provide it as

[id]='variableName'

so that the variableName will be the element reference ID.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.