JavaScript ngClass OR expression ngclass expressionchangedafterithasbeencheckederror,ngclass expression example,ngclass expression angular 6,ngclass

I have an element with ng-class attribute like this:

<label class="item item-input item-floating-label"
              ng-class="{'has-errors':{{loginForm.$submitted && loginForm['AccountLoginForm[username]'].$invalid}} || {{loginForm.$submitted && loginForm['AccountLoginForm[username]'].$valid && success.data.login=='err'}},
                         'no-errors':{{loginForm.$submitted && loginForm['AccountLoginForm[username]'].$valid}} || {{loginForm.$submitted && loginForm['AccountLoginForm[username]'].$valid && success.data.login=='ok'}}">
</label>

But classes aren't applying. What I did wrong and what is the best way to write an expressions like this?

Answer:1

You can write JavaScript expression inside ng-class. You don't need more braces {{}}:

<label class="item item-input item-floating-label"
              ng-class="{'has-errors':(loginForm.$submitted && loginForm['AccountLoginForm[username]'].$invalid) || (loginForm.$submitted && loginForm['AccountLoginForm[username]'].$valid && success.data.login=='err'),
                         'no-errors':(loginForm.$submitted && loginForm['AccountLoginForm[username]'].$valid) || (loginForm.$submitted && loginForm['AccountLoginForm[username]'].$valid && success.data.login=='ok')">
</label>
Answer:2

The code that you have posted will work once you remove the curly braces {{}}. Logical operators are allowed within ng-class. But the better way would be to create a function and make that function return either true or false on the number on conditions that you want to test and then call that function from ng-class.

<label ng-class="{'classOne':check(), 'classTwo': checkAgain()}"></label>
Answer:3

Setting width for <li> tags not working. Width is changing based on content for <li> tag below is the html code Without using display: block/table/inline-block; <!DOCTYPE ...

Setting width for <li> tags not working. Width is changing based on content for <li> tag below is the html code Without using display: block/table/inline-block; <!DOCTYPE ...

  1. javascript setting width of element
  2. javascript setting width

<li ng-repeat="appliance in appliances | limitTo:2"> <div class="icon"> <img src="images/vector/Appliances/w-{{appliance.DashboardIcon}}.svg"> </div> <div ...

<li ng-repeat="appliance in appliances | limitTo:2"> <div class="icon"> <img src="images/vector/Appliances/w-{{appliance.DashboardIcon}}.svg"> </div> <div ...

I searched the internet for answer but when I couldn't find one, I am posting my question. Is there any way we can detect if a site is being used by computer or mobile? I don't want to use the ...

I searched the internet for answer but when I couldn't find one, I am posting my question. Is there any way we can detect if a site is being used by computer or mobile? I don't want to use the ...

I'm new to Cytoscape.js and trying to draw a graph with the help of Dagre layout depending on users' search input. Number of nodes is typically 50-100. Although Dagre works well for a single tree, ...

I'm new to Cytoscape.js and trying to draw a graph with the help of Dagre layout depending on users' search input. Number of nodes is typically 50-100. Although Dagre works well for a single tree, ...

  1. deal with multiple tasks
  2. deal with multiple job offers
  3. deal with multiple stakeholders
  4. deal with multiple personality
  5. deal with multiple health issues
  6. mysql deal with multiple time zones
  7. deal multiple
  8. deal multiple definition
  9. how to deal with multiple personality disorder
  10. how to deal with multiple deaths
  11. how to deal with multiple sclerosis
  12. how to deal with multiple miscarriages
  13. how to deal with multiple deadlines
  14. how to deal with multiple offers real estate
  15. how to deal with multiple offers on a house
  16. how to deal with multiple priorities
  17. approaches to deal with multiple interrupts
  18. how to deal with multiple rejections
  19. how to deal with multiple job rejections
  20. how to deal with multiple losses