[英]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> <b>{{selected_FacultyorStudent}} <i class="fa fa-angle-down" style="font-size: 0.7em; font-weight: 700;"></i></b> ·<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.在您的 FacultyorStudent_Data 数组中,通过循环对其进行迭代,如果项目等于您要删除的项目,则进行匹配。 If they match then remove it using splice method.如果它们匹配,则使用拼接方法将其删除。
In you.ts file:在 you.ts 文件中:
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') } }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.