A.khalifa
A.khalifa

Reputation: 2496

Change behavior inside ng-repeat Angularjs


I get an array of string like this ["create-user", "edit-user", "read-user", "delete-user"] in console, now i want to pass it to view .
My code :

  <tr ng-repeat="perm in permsAll">
        <td>
            {{perm == "create-user" : X ? ' '}}
         </td>
          <td>
            {{perm == "create-edit" : X ? ' '}}
         </td>
         ....
 </tr>

So i get all strings but not that what i want :( , i want if user have create-user for example make a X in td example userX = createUser: X if not have create-use it will be empty .

How to do it ? , i guess i must to use directive. and thanks ?

Upvotes: 0

Views: 73

Answers (2)

sexta13
sexta13

Reputation: 1568

You can do it in different ways.

You can try to use a ng-switch or a ng-if or even a ng-show.

For example:

<td ng-if="perm.contain === 'create-user'>X </td>

If you want to use the code you have you have to change for something like:

<td>
   {{perm.contain === 'create-user' ? 'X' : ' '}}
</td>

edited: added literal string

Upvotes: 3

Gustavo Gabriel
Gustavo Gabriel

Reputation: 1296

You are trying to use the wrong operator, try this:

{{perm.contain == "create-user" : X ? ' '}}

But your best bet would be like sexta said:

<td ng-show="perm.contain == 'create-user' ">X</td>

Hope it helps =)

Upvotes: 2

Related Questions