angularjs带过滤器选择过滤掉的已经选择的选项 [英] angularjs Select with filter to filter out the option that's already selected

查看:149
本文介绍了angularjs带过滤器选择过滤掉的已经选择的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的code的选择与NG-模型做工精致,除了过滤器的东西。
如果没有过滤器,它显示为已选择了一个重复的选项..
所以,我想筛选出低于code已选定的那一个。

但它不工作..难道我做错了什么?任何帮助吗?

 <选择NG模型=result.color>
<选项NG重复=!codeS在OBJ codeS |过滤器:result.colorVALUE ={{codeS code}}> {{codeS code}}< /选项>
<选项NG选择> {{result.color}}< /选项>
< /选择>


解决方案

NG-选择接受一个前pression。
这是我会做什么:

 <选项NG重复=codeS在OBJ codeSVALUE ={{codeS code}}NG -selected =result.color == codeS code。>


== ==编辑

另外一个更短的解决办法是使用 NG-选项

 <选择NG模型=result.colorNG选项=。C code代表在OBJ C codeS>< /选择>

下面是小提琴: http://plnkr.co/edit/oIysU5

不知道的初始值作为我的小提琴似乎工作。

My code for select with ng-model is working fine except filter stuff. Without filter, it's showing duplicated option for the already selected one.. So I am trying to filter out the one already selected in below code.

But it's not working.. Am I doing something wrong? any help please?

<select ng-model="result.color">
<option ng-repeat="codes in obj.codes | filter:!result.color" value="{{codes.code}}">{{codes.code}}</option>
<option ng-selected>{{result.color}}</option>
</select>

解决方案

ng-selected accepts an expression. This is what I would do:

    <option ng-repeat="codes in obj.codes" value="{{codes.code}}" ng-selected="result.color == codes.code">


== edit ==

another even shorter solution would be to use ng-options.

<select ng-model="result.color" ng-options="c.code for c in obj.codes"></select>

Here is the fiddle: http://plnkr.co/edit/oIysU5

Not sure about the initial value as my fiddle seems working.

这篇关于angularjs带过滤器选择过滤掉的已经选择的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆