angularjs - Checking size of an array -
I have an array that always gives 20 items
for example, with 20 items myArray (only 15 values)
$ scope.myArray = ["1", "2", "3", "4", "5", " 6 "," 7 "," 8 "," 9 "," 10 "," 11 "," 12 "," 13 "," 14 "," 15 "," "," "," "," " , ""] I want to show / hide / show a ng, on some elements, depending on the number of people in the items in my field.
Basically I tried:
& lt; Div ng-show = "myArray.length> 10" & gt; If more than 10 items & lt; / Div & gt; & Lt; Div ng-show = "myArray.length> 15" & gt; Show that more than 15 items & lt; / Div & gt; & Lt; Div ng-show = "myArray.length> 1 9" & gt; If more than 19 items & lt; / Div & gt; Naturally, all of the above mentioned will show because always return 20 items.
Can I get it ng-show / hide / if and without having to write additional JS in my controller?
Filter just the empty items:
var outBlanks = boolean; $ Scope.nonBlanksCount = $ scope.myArray.filter (outBlanks). Length; & Lt; Div ng-show = "non blancasank> 10" & gt; If more than 10 items & lt; / Div & gt; I have just read that you did not want to add any argument to your controller. In this case, you can write a custom filter (such as filterBlanks ) which are mentioned above Same works and does:
& lt; Div ng-show = "(MyArray | filterBlanks), length> 10" & gt; If more than 10 items & lt; / Div & gt; However in this case, the filter will be executed multiple times, which is not very efficient.
Comments
Post a Comment