简体   繁体   English

在 p-dropdown 中禁用某些 ng-template 项

[英]Disable certain ng-template items in p-dropdown

I have a p-dropdown contructed with ng-template (this dropdown presents Languages that can be selected.) I need the languages that have been already selected, to be disabled .我有一个用ng-template构建的p-dropdown (这个下拉列表显示可以选择的语言。)我需要已经选择的语言,要disabled

This is my dropdown:这是我的下拉列表:

<p-dropdown 
  [styleClass]="'form-control'" 
  [options]="languages" 
  optionValue="languageID" 
  formControlName="languageID" 
  appendTo="body"
  (onChange)="onLanguageChanged(languagesFormGroup, $event.value)">
    <ng-template let-item pTemplate="selectedItem">
      <img src="{{item.icon}}"><span>{{item.name}} {{item.languageID}}</span>
    </ng-template>
    <ng-template let-item pTemplate="item">
      <img src="{{item.icon}}"><span>{{item.name}} {{item.languageID}}</span>
    </ng-template>
</p-dropdown>

I need specific pTemplate="item" to be disabled.我需要禁用特定pTemplate="item" I tried with angular's disable , i tried with ng-disable , with ngIf , with [att.disabled]="expression(item)" , nothing works.我尝试使用 angular 的disable ,我尝试使用ng-disable ,使用ngIf ,使用[att.disabled]="expression(item)" ,没有任何效果。

Is there any way to achieve what I need?有什么办法可以达到我的需要吗? Please help.请帮忙。

Thanks a lot in advace非常感谢提前

So I found the correct way to do it.所以我找到了正确的方法。 I added a disabled property on my languages collection.我在我的languages集合中添加了一个disabled属性。 I set disabled = true whenever a language is selected and the ng-template does the rest by itself. I set disabled = true whenever a language is selected and the ng-template does the rest by itself. No further code needed.无需进一步的代码。

Thanx everyone for their suggestions!感谢大家的建议!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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