Dropdown

I need to hide and show the dropdown  *ngIf="showTask"

when i show the dropdown, i am not able to access the dropdown, it shows null

  @ViewChild('ddTask'public ddTaskDropDownList;

 <div class="col-md-3  mt-2" *ngIf="showTask">
                <ejs-dropdownlist #ddTask name="task" class="e-error ts-bold" (change)="taskChange($event)"
                id='task' [dataSource]='aBacklogs' [fields]='taskFields'
               floatLabelType='Auto'></ejs-dropdownlist>
                <!-- [(ngModel)]="itemId"  [allowFiltering]='true'  placeholder='Select Task' -->
            </div>


I am trying to set the selected index when showTask is true.
But ddTask is still not ready!!. i tried with seTimeout function. work randomly.



 if(this.ddTask){
        this.ddTask.index =0;
        }

1 Reply 1 reply marked as answer

BC Berly Christopher Syncfusion Team June 3, 2021 07:52 AM UTC

Hi Vin, 
  
Greetings from Syncfusion support. 
  
We have checked the reported issue. When we toggle the component, its instance was not created at that time. Due to this time delay, the index property was not set to the component properly. So, we suggest you to assign the index value in the ngAfterViewChecked life cycle hook which is invoked each time the view of the given component has been checked by the change detection mechanism. 
  
Kindly refer the below code example. 
  
  toggle() { 
    this.isShown = !this.isShown; 
  } 
  ngAfterViewChecked() { 
    if (this.isShown) { 
      this.DropObj.index = 0; 
    } 
  } 
 
  
  
Regards, 
Berly B.C 


Marked as answer
Loader.
Up arrow icon