简体   繁体   中英

remove selected option from drop-down available options

I have a drop-down and I need to remove the selected option and show the remaining options. thanks in advance

 FacultyorStudent_Data: Array<string> = ['Faculty/Coach','Student'] selected_FacultyorStudent: string = this.FacultyorStudent_Data[0]; SelectFacultyorStudent(FnS){ this.selected_FacultyorStudent=FnS; }
 <div class="text-center" id="perf-type" *ngIf="section=='practice'"> <h4 class="dropdown-toggle" data-toggle="dropdown"> <i class="fa fa-bar-chart" aria-hidden="true"></i> &nbsp; <b>{{selected_FacultyorStudent}} &nbsp; <i class="fa fa-angle-down" style="font-size: 0.7em; font-weight: 700;"></i></b>&nbsp;&middot;<small>beta v4</small> </h4> <ul class="dropdown-menu" style="width: 20%; left: 40%;color: #337ab7;"> <li *ngFor="let item of FacultyorStudent_Data; let i = index;" class="text-center" [ngClass]="{'bg-selected-quiz': selected_FacultyorStudent==item}" (click)="SelectFacultyorStudent(item)"> {{item}}</li> </ul> </div>

In your FacultyorStudent_Data array iterate it through loop, and match if item is equals to the item you want to remove. If they match then remove it using splice method.

In you.ts file:

for(let i=0;i<this.FacultyorStudent_Data.length;i++){
   if(FacultyorStudent_Data[i]=='yourItemName'){
     this.FacultyorStudent_Data.splice(i,1)
   }
}

 if (FnS == 'Student'){ this.FacultyorStudent_Data.splice(0,1,'Faculty | Coach Insights') } else{ this.FacultyorStudent_Data.splice(0,1,'Student') } }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM