0

Here my html-

     <p  ng-if= "editMode=='edit'" style="margin-left: 1px;margin-top: -2px;">===some messages---</p>
     <p  ng-if= "editMode=='addNew'" style="margin-left: 1px;margin-top: -2px;">===some messages---</p>

In above example i have two diffrent view "edit" and "addNew" with same content but style is different. How to do that?

3
  • i just tried using ng-if .. But code won;t look good.. any other suggestion? Commented Dec 22, 2015 at 9:28
  • please provide your full html with your controller Commented Dec 22, 2015 at 9:29
  • Use ng-style. Based on the expression evaluation the style is determined. Commented Dec 22, 2015 at 9:29

1 Answer 1

0

You can use ng-class:

<p ng-class='{"class1": editMode=="edit", "class2": editMode=="addNew"}'>===some messages---</p>

And in css file:

.class1 {
     /* some styles */
}
.class2 {
     /* some styles */
}

However there are many more built in directives in AngularJS that you can use. For a more detailed explanation about the options available and with examples, take a look at the accepted answer for a similar question

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

2 Comments

But if i want to add it in inline itself? is there anyway?
@saurav You can use ng-style for inline style.

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.