Filter options by value in another selectbox
TheYves opened this issue · comments
I have two selectboxes and the second one filters its options depending on the value of the first selectbox. This actually works, but the console is full of "Infinite $digest Loop" errors. The reason for these errors lies on line number 160 in the file angular-select2-1.3.8.js. When I remove the $watch, the errors disappear. The selectbox still works, at least it looks so. I'm not sure if this $watch is really needed or not. Maybe someone can help me here.
Here's a Plunker: http://plnkr.co/edit/pBe8eCs0C3DxGfdgIfZx?p=preview
Plunker seems to error out: GET http://api.plnkr.co/proxy.html 500 (Internal Server Error)
, so I can't see your code.
Would you mind throwing it on jsFiddle or gist?
Thanks for your reply. I guess they had some temporary server problems, it should work now. Otherwise, I'll put it on jsFiddle.
This is an Angular problem (Angular gives trouble when binding filtered values to directives).
In other words, your problem is here:
ng-options="val.id as val.name for val in values2 | myFilter: model1"
I haven't found a way to make this work and from the looks of it, we're not the only ones looking.
As a workaround, we added a options-filter
parameter, which you can use instead:
ng-options="val.id as val.name for val in values2" options-filter="myFilterFunc"
Where myFilterFunc
is a function that takes the val
and returns true
or false
.
Let me know if that works for you.
Oh and you can pass any $filter
argument to options-filter
, so either a function, or something like this:
options-filter="{ isarchived: false }"
Oh my... It was always there... the whole time...
It works perfectly! Thank you very much!