0

I'm using ng-style in angularJs to style an element like the following the first part is conditional style that depends on the value of isEdit if it's true pass empty object if not set color to grey , the second style should be applied regarless of the first part.

the code I used didn't seem to work

ng-style="isEdit? {}: {'color': 'gray'}, leftStyle"

is there a way to chain the 2 styles and make them work at once ?

1 Answer 1

1

We can achieve that by merging the styles in a method and then calling it in template

<h1 ng-style="isEdit ? {} : getStyles()">
    {{ heading }}
</h1>
var style1 = {
  color: "white",
  "background-color": "coral",
  "font-size": "60px",
  padding: "50px",
};

function _getStyles() {
  return Object.assign({}, style1, {
    border: "3px solid black",
  });
}

Working Demo

Sign up to request clarification or add additional context in comments.

Comments

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.