0

trying to match value from passed array and loop on the page

.then(function (data) {
    vm.outputL = data;
    vm.array = [];

    for(var i=0; i < vm.outputL.length; i++){

        vm.block = false;       
        if(vm.outputL[i].id < 100){

            vm.block = true;

        }

        vm.array.push(vm.block) 

    }
}

and html code

 <li ng-repeat="item in vm.outputL">
    <div>{[item.id]}</div>
    <div ng-if="vm.array">something</div>
 <li>

how can I match value from vm.block and loop item on the page?

5
  • 1
    what do you want to do exactly? also share more of your HTML code Commented Mar 31, 2017 at 10:34
  • @tanmay I would like to match value from vm.array with item in loop Commented Mar 31, 2017 at 10:39
  • So, you want to show something when it's id is less than 100. Is that right? Commented Mar 31, 2017 at 10:40
  • that was just a simple example I have more complex stuff, I just want to see how to match value from passed array and item within loop Commented Mar 31, 2017 at 10:41
  • @user1751287: Please check this fiddle. Is this something you require? jsfiddle.net/HB7LU/28608 Commented Mar 31, 2017 at 11:18

1 Answer 1

1

They way you handle data results vm.array and vm.outputL to have different length.

If I am not mistaken, what might be useful based on your question is to push vm.block without caring about its value so that you can match it to the itterating items.

This block might be useful:

Controller:

    vm.block = false;       
    if(vm.outputL[i].id < 100){
       vm.block = true;   
    }
    vm.array.push(vm.block) 

Template:

<li ng-repeat="item in vm.outputL">
    <div>{[item.id]}</div>
    <div ng-if="vm.array[$index]">something</div>
 <li>
Sign up to request clarification or add additional context in comments.

4 Comments

vm.array and vm.outputL actually have the same length, if you look at my code vm.block = false is also in a loop so both true and false will be in array hence the same length
You are pushing the vm.block only when if statement results true value.
then all you have to do is check the template block quote I've submitted
yeah I can immediately see that $index was missing, let me try it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.