5

I have recieved object from server and trying to display its fields in table. All fields are displaying well but boolean is always displaying 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 was trying to add filter, but result was the same.

9
  • 2
    Hi. Are your sure that isAdmin is not false for all users? Try to display like this: <td><span ng-bind="u.isAdmin" ></span></td> and see what you got Commented Mar 18, 2016 at 13:30
  • or maybe undefined ? Commented Mar 18, 2016 at 13:31
  • I'm sure that isAdmin is not false for all users. Commented Mar 18, 2016 at 13:36
  • 2
    @Geha It appears your object doesn't have an isAdmin property, so try the following to print out it's entire contents <pre>{{u | json}}</pre> Commented Mar 18, 2016 at 13:48
  • 1
    @CaffGeek, when I use this <pre>{{u | json}}</pre> , I see that "admin" : true. I was using wrong name of property. Thank you so much! Commented Mar 18, 2016 at 13:58

2 Answers 2

2

Double check you have the property name right in code.

You can print the u object as json with

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

I'm pretty sure that if the value is in the database and isn't false or null, then you have the name wrong, and it's not isAdmin but something else.

EDIT: Looks like I was right and you were using the property name admin instead.

Sign up to request clarification or add additional context in comments.

Comments

0

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

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

5 Comments

Downvoter comment please.I hope you know the exact reason
The reason is that @Geha said in a comment of its post, that the isAdmin property doesn't display anything. Your answer is then invalid.
@Erazihel the OP also stated originally in his question that All fields are displaying well but boolean is always displaying as "no". which conflicts his latter comment. I think the OP was incorrect in the comment as u.isAdmin be it undefined or otherwise will get evaluated as a truthy/falsy expression. To render "nothing" doesn't seem possible unless Angular is throwing an exception somewhere which wasn't mentioned. I think the downvote is excessive.
@jusopi It doesn't conflict with the latter comment as the result would be no even if the boolean was undefined.
All fields are displaying well but boolean is always displaying as "no". vs When I do like this: <td><span ng-bind="u.isAdmin" ></span></td> , nothing is displayed are indeed two different things. Please reread my comment.

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.