Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
65
rated 0 times [  72] [ 7]  / answers: 1 / hits: 31302  / 11 Years ago, wed, october 2, 2013, 12:00:00

I've been searching for a few hours now and I can't seem to find the answer for my problem anywhere. I remember that I was able to implement it before but for some reason I lost the code and I can't seem to remember what I did to make it work.



I'm trying display data from an array in a select box using ng-options. That one I have no problems with. What I need to implement is that only certain array values will be displayed/included in the select box.



My data is as follows:



$scope.chartList = [ { id : 1, name : chart 1, order : 1, active : false },
{ id : 2, name : chart 2, order : 2, active : true },
{ id : 3, name : chart 3, order : 3, active : true },
{ id : 4, name : chart 4, order : 4, active : true },
{ id : 5, name : chart 5, order : 5, active : true } ];


And my HTML looks like:



<select ng-model=toAddChart ng-options=chart.id as chart.name for chart in chartList | filter:chart.active=='false'>
<option value=></option>
</select>


So what I want to happen is that if the value of the attribute active is false then it's the only time the array item will be displayed/included in the select list. I've tried different permutations of the filter attribute but none seem to work.



I know I can easily use ng-repeat in the tag and use ng-show but I remember reading somewhere (again, I can't find where) that it's not the proper way to implement it and that using ng-options is the correct way.



I'm really really sure I was able to do it before without creating a custom javascript filter, but for the life of me I can't remember how I did it. I'm hoping someone can



Hope someone can help me with this because I'm out of ideas.



Update:



Great scott, I think I've got it.



Instead of:



filter:chart.active=='false'


It should be:



filter:chart.active='false'


It's just the number of equal signs used. facepalm



Thanks for the responses, everyone.


More From » angularjs

 Answers
21

Great scott, I think I've got it.



Instead of:



filter:chart.active=='false'


It should be:



filter:chart.active='false'


It's just the number of equal signs used. facepalm



Thanks for the responses, everyone.


[#75287] Tuesday, October 1, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
admin

Total Points: 468
Total Questions: 103
Total Answers: 103

Location: Equatorial Guinea
Member since Sun, Feb 14, 2021
3 Years ago
admin questions
Tue, Dec 29, 20, 00:00, 4 Years ago
Sun, Aug 16, 20, 00:00, 4 Years ago
Fri, Jul 31, 20, 00:00, 4 Years ago
Mon, Oct 14, 19, 00:00, 5 Years ago
Sun, Jun 16, 19, 00:00, 5 Years ago
;