Angularjs mapping logical entities

I received the object from the server and tried to display its fields in the table. All fields are displayed well, but a boolean value is always displayed as "no."

<tr ng-repeat="u in ctrl.users"> <td><span ng-bind="u.id"></span></td> <td><span ng-bind="u.name"></span></td> <td><span ng-bind="u.age"></span></td> <td><span ng-bind="u.isAdmin ? 'yes' : 'no'" ></span></td> </tr> 

I tried to add a filter, but the result was the same.

+5
source share
2 answers

Double check that you have a property name right in the code.

You can print the u object as json with

 <pre>{{u | json}}</pre> 

I am sure that if the value is in the database and is not false or null, then you have the wrong name, not isAdmin , but something else.

EDIT: Looks like I was right, and you used the admin property name instead.

+2
source

When you return the boolean value from an ajax call, you always get it as a string . So you need to check it out like this

 <span ng-bind="name =='true'? 'yes' : 'no'"></span> 
0
source

Source: https://habr.com/ru/post/1245320/


All Articles