Anurag Ranjan
Anurag Ranjan

Reputation: 252

How to display a div on selecting a dropdown option

I am creating a form where I have a dropdown list when user selects the option

Software developer

a new div is displayed , with two option

  1. App Developer
  2. Web Developer

I am giving code below -:

html code -

<div class="form-group">
         <label for="dept"> Departmant </label>
         <select id="dept" (change)="fun()" class="form-control" class="form-control" name="departmant" [(ngModel)]="departmant">
           <option value="1"> HelpDesk </option>
           <option value="2"> Hr</option>
           <option value="3"> Software Engineer </option>
           <option value="4"> System Admin </option>
        </select>
         </div>

<div class="form-group" *ngIf="doninSe">
        <label for="domin"> Domain: </label>
        <select id="domin" class="form-control" name="domin" [(ngModel)]="domin">
          <option *ngFor="let domins of Domin"> {{domins.name}}  </option>
        </select>
</div>

ts code -:

export class CreateEmployeeComponent implements OnInit {
  DominSe: boolean = True ;

constructor() { }

  Domin: Departmants[] =
                   [{id: 1 , name: 'App Developer' },
                    {id: 2 , name: 'Web Developer'},
                  ];


  ngOnInit() {
  }

}

Also I am getting error while defining DomineSe variable

DominSe: boolean = True ;

getting error -:

[ts] Cannot find name 'True'.
any

Upvotes: 0

Views: 35

Answers (2)

Aniket Avhad
Aniket Avhad

Reputation: 4145

boolean value should be true not True and also use the same variable name in html as you declared in .ts

here's is example

<div class="form-group" *ngIf="dominSe">
     <label for="domin"> Domain: </label>
     <select id="domin" class="form-control" name="domin" [(ngModel)]="domin">
         <option *ngFor="let domins of Domin"> {{domins.name}}  </option>
      </select>
</div>

and in .ts

dominSe: boolean = true;

Upvotes: 0

Sachila Ranawaka
Sachila Ranawaka

Reputation: 41445

should be true

DominSe: boolean = true;

Upvotes: 1

Related Questions