Alon
Alon

Reputation: 7758

How to create a condition in the HTML using AngularJS

I have this object

people = [{name: "John", registered: true },{name: "Micky", registered: false },{name: "Carol", registered: true }]

and I have this angular HTML:

<ul>
  <li ng-repeat="person in people">
    {{person.name}}
    <div class="already-registered-icon">&nbsp;</div>
  </li>
</ul>

My question is - how do I make a condition to display the registered icon only when the user is already registered?

I would think of something like this (but I don't know how it can be written):

{{if person.registered}}
        <div class="already-registered-icon">&nbsp;</div>
{{end}}

Upvotes: 0

Views: 464

Answers (2)

Alon
Alon

Reputation: 7758

It was the ng-show attribute I was missing

<ul>
  <li ng-repeat="person in people">
    {{person.name}}
    <div ng-show="person.registered" class="already-registered-icon">&nbsp;</div>
  </li>
</ul>

Upvotes: 0

Yoshi
Yoshi

Reputation: 54649

Just use ngShow:

<div ng-show="person.registered" class="already-registered-icon">&nbsp;</div>

demo: http://jsbin.com/usodaw/1/

Upvotes: 2

Related Questions