javascript - AngularJS: ngIf in array of objects with different properties -


i have issue ngif directive. tried lot of ways resolve it, unfortunately failed.

i have array of objects different properties. this:

    object = [     {         name: "1",         isnumber: true,     },     {         name: "2",         isnumber: true,     },     {         name: "3",         isnumber: true,     },     {         name: "4",         isnumber: true,     },     {         name: "5",         isnumber: true,     },     {         name: "#",         isnumber: false,     },     {         name: "*",         isnumber: false,     } 

i need use ngif on last object true value of isnumber property. don't know how objects isnumber on true in array. can 7 or 82. nobody knows. objects isnumber on false won't in array. array have objects isnumber on true , no objects isnumber on false.

how can achieve using ngif?

thanks in advance.

update:

i have this:

1, 2, 3, 4, 5, 6, 7, *, #.

and don't want have "down" button on last element true value of isnumber property (7 in case). because if user moves down, i'll have this:

1, 2, 3, 4, 5, 6, *, 7, #.

and wrong logic.

so, need use ngif, disable button on element. can have smth (without symbols):

1, 2, 3, 4, 5.

and in situation don't need "down" button on last element too. because it's impossible move last element down.

if you're trying find if it's last element , if isnumber set true, can use this:

<span ng-repeat="item in items" ng-if="item.isnumber && $last">

$last special variable defined through ngrepeat, located here. since ngif accepts boolean statement, can use both logical && , || operators.

edit: if you're not iterating on ngrepeat , want select last element, can select last one, use ngif display if isnumber set true:

<span ng-bind="list[list.length - 1]" ng-if="list.isnumber">

edit 2: "peek" @ next element , see if next isnumber set false? this:

<span ng-repeat="...">    <span ng-if="!list[$index + 1].isnumber"></span> </span> 

like $last, i'm using special variable called $index go next element in ngrepeat. (not sure if angular automatically checks out-of-bounds errors, or if it'll throw error)


Comments