ng-if is not working as expected.

Swati44
Kilo Expert

Hi All,

<td ng-if="item.response_code == '300'"> <button id="btnIncident" name="submit" ng-click="c.remove(item.name)" type="submit">Remove</button></td>
</tr>

 

The above line is not working as expected, Remove button is not visible all time, irrespective of response code.And it is visible and working as expected if i remove 'ng-if="item.response_code == '300'"'.

How to compare the item.response_code value?

 

Thanks & Regards,

Swathi.

1 ACCEPTED SOLUTION

I forget sometimes how javascript works. This should do the trick:

item.response_code === '300'

Depending upon the situation javascript interprets '300' and 300 as being equal or the same. Whereas if you use the equality where it checks the type as well then it will prove to be actually an integer vs a string version of 300.

 

But to answer your other question how to compare without ng-if:

Simply place the expression in the markup:

<div> {{ item.response_code === '300' }} </div> 

That syntax is what is doing the comparison. ngIf is just looking for a result.

View solution in original post

13 REPLIES 13

can you change in your server side script. isnted using item try with data.

 

<td ng-if="{{data.response_code}}=='300' "> <button id="btnIncident" name="submit" ng-click="c.remove(item.name)" type="submit">Remove</button></td>
</tr>

 

just give a try 

Ujjawal Vishnoi
Mega Sage
Mega Sage

Hi Swathi,

 Syntax is corret. I doubt you item.response_code is not having expected value and hence not rendering the markup.

 

Hope this helps.

Regards,

Ujjawal

Hi Ujjawal,

 

It is having proper value, 300.

Hi Swathi,

 

Can you paste your widget code. So that issue could be identified.

Regards

Ujjawal