M Nouman
M Nouman

Reputation: 591

Can not find control with unspecified name attribute Angular 14

I'm facing the the following error.

enter image description here

And when I click at the line pointed with BLUE ARROW in the above image, it points to of of ngFor loop in my html template.

     <div class="w-[60%]">
       <select
        name="duration"
        id=""
        class="text-[1rem] leading-6 py-2 px-8 border border-[#BCBCBC] w-[27.875rem] rounded-md focus:outline-none focus:border-primary"
        [formControl]="demoLength"
        required
      >
        <option
          [value]="timing.value"
          *ngFor="let timing of staticDurationArray"
          selected="{{ timing.selected }}"
        >
          {{ timing.time }}
        </option>
      </select>
    </div>

And in the above code the staticDurationArray is an array with static data in TS file

staticDurationArray = [
    {
      time: '15 min',
      value: 15,
      selected: '',
    },
    {
      time: '30 min',
      value: 30,
      selected: '',
    },
    {
      time: '45 min',
      value: 45,
      selected: '',
    },
    {
      time: '1 hr',
      value: 60,
      selected: '',
    },
]


       
         

Upvotes: 2

Views: 4820

Answers (1)

M Nouman
M Nouman

Reputation: 591

I found the answer I tried by putting an *ngIf condition to my piece of code and the issue is solved

<div class="w-[60%]">
              <select
                *ngIf="demoLength"
                [formControl]="demoLength"
                name="duration"
                id=""
                class="text-[1rem] leading-6 py-2 px-8 border border-[#BCBCBC] w-[27.875rem] rounded-md focus:outline-none focus:border-primary"
                required
              >
                <option
                  [value]="timing.value"
                  *ngFor="let timing of staticDurationArray"
                  selected="{{ timing.selected }}"
                >
                  {{ timing.time }}
                </option>
              </select>
            </div>

Upvotes: 3

Related Questions