简体   繁体   English

Angular 4中用于Json对象数组的自定义管道过滤器

[英]Custom Pipe Filter For Array Of Json Objects In Angular 4

I have an array, that consists a list of json objects as items. 我有一个数组,其中包含作为项目的json对象的列表。 I am using this array as an options list for two select controls, here I want to hide first select control selected items in second select control options list. 我将此数组用作两个选择控件的选项列表,在这里我要隐藏第二个选择控件选项列表中的第一个选择控件选择项。

Is it possible to do? 有可能吗?

I don't know why are you looking for a pipe/filter solution when it can be done so easily without pipe? 我不知道为什么不使用管道就可以如此轻松地完成管道/过滤器解决方案? I may not be knowing entire scenario of yours but what you have written according to that a simple solution would be, 我可能不知道您的整个情况,但是您根据一个简单的解决方案写的内容是,

<select class="form-control" [(ngModel)]="selectedCity">
     <option *ngFor="let ct of cities" [value]="ct.id">{{ct.name}}  
</select>



// look at [disabled]="selectedCity==ct.id"

 <select class="form-control" [(ngModel)]="selectedOtherCity">
     <option [disabled]="selectedCity==ct.id" *ngFor="let ct of cities" [value]="ct.id">{{ct.name}}  
</select>

detailed code could be found here : https://plnkr.co/edit/gkvFqtyddLVEsFOE07Ls?p=preview 可以在这里找到详细的代码: https : //plnkr.co/edit/gkvFqtyddLVEsFOE07Ls?p=preview

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

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