1

I have a layer with ng-class, and I need to use user.status with ng-class. and I have another class that I want to bind on the same layer.

<div ng-class="user.status, 'locked':(user.active === '0')">

but whats the correct way of doing this? somehow it does not work.

2
  • 1
    Bad title. you could change it to a full question or at least a short description to your question. Commented Oct 4, 2014 at 23:55
  • 1
    yes, you right! I have changed the title Commented Oct 4, 2014 at 23:58

1 Answer 1

1

One of the ways is to use class and ng-class:

<div ng-class="{'locked':(user.active === '0')}" class="{{user.status}}">

UPDATE

This should work without interpolation:

<div ng-class="{user.status: true, 'locked':(user.active === '0')}">
Sign up to request clarification or add additional context in comments.

7 Comments

Need to check, but maybe putting what you have in brackets should work: <div ng-class="{user.status, 'locked':(user.active === '0')}">
yes but I have alot of users, and interpolating adds many watchers on the page. I am trying to do it in ng-class. I actually use bindonce which can be called sameway like ng-class
I will check it shomz
no it does not work <div ng-class="{user.status, 'locked':(user.active === '0')}">
Well, ng-class also uses watcher, I'm not sure about the performance, but you shouldn't be able to see the difference. I thought <div ng-class="{user.status: true, 'locked':(user.active === '0')}"> might also work, but probably not without another interpolation.
|

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.