Help with ng-if and server script

robhaas
Tera Contributor

I have a list of items and each has an order. I have another variable that is set to the current record's order. I am trying to print all items that have been completed thus far. So for example:

List:

LabelOrder
Step11
Step22
Step33
Step44

I query this table and push all rows into something named steps. I also get the current record's step number and store it in a variable steps.rec. Example:

steps.rec = 3;

In my html, I have an ng-repeat:

<div ng-repeat="step in c.data.steps">

This if followed up with a ng-if:

<div ng-if="steps.order <= steps.correct">

                          {{steps.label}}

                      </div>

The problem here is that I am only printing the current record label, not the ones before it. I should be printing Step1, Step3, Step3. I am only getting step3. Any thoughts?

6 REPLIES 6

Andrew Wortham
Kilo Guru

Hey Robert,



It would be really helpful to see the full server script that you are using with this HTML. I would need to do some trouble shooting here. You have "steps.correct" listed but not populated above, I assume it's set to "steps.rec"? But without the full code, I can only offer some trouble shooting advice.



When you are creating the object for data.steps are you ensuring that the properties you are populating throughout the GR are being turned into strings?   (We have all been burned by that one).



What happens if you remove the "ng-if" How many {{steps.label}}s end up printing?   Are all 4 there?   Are all 4 the correct values?



Best,


Andrew


All 4 show if I remove the ng-if. Basically it seems as though my condition of <= is not calculating correctly. I have tried both setting the properties to strings and not doing so. Neither seem to work. I would think I need integers instead of strings, but no luck.



For reference, when I do a gs.log, I get the correct values for all steps and the current step.


Hey Robert,



Try



<div ng-if="steps.order <= steps.correct">


                          {{::steps.label}}


                      </div>




The :: in the expression will cause it to stop calculating, rather than binding to steps.label, which keeps getting re evaluated.



Let me know if that works.



Best,


Andrew


That shows the current step which is =, but not the < values.