0

I'm new to angular and I had this problem last 2 day on how to concatenate dynamic class name in angular 2. Like this code in react.js className=this-is-a-str${isFoo? 'add this' : 'then this'} something like that in angular. heres my code in anguar.

[className]="getDesignStatus(design).hasError ? 'project--btn btn btn-action btn-danger-invert col-md-3 col-lg-3' : 'project--btn  btn btn-action btn-primary-invert col-md-3 col-lg-3'"

the string that only changing is these 2 btn-danger-invert && btn-primary-invert

1 Answer 1

2

Just rename className to ngClass and add static classes using regular html class attribute

<div 
  class="project--btn btn btn-action col-md-3 col-lg-3" 
  [ngClass]="getDesignStatus(design).hasError ? 'btn-danger-invert' : 'btn-primary-invert'"
></div>
Sign up to request clarification or add additional context in comments.

2 Comments

holy crap dude. you saved a life! thank you so much!
No worries, mate :)

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.