4

I currently have the following expression in ng-class, in the view of an AngularUI Bootstrap modal:

<div class="modal-body mdl-body" ng-class="{ 'is-msg': vm.message.type == 'msg', 'height-limit': vm.message.hasHeight }"> 

But I also want to pass an array of custom classes, like this:

ng-class="vm.message.classes" 

This is where the modal is called in controller:

modalService.open({ type: "okay", title: "Terms & Conditions", content: $scope.APISettingData.signup_term_and_condition, classes: ["h-md", "text-info"], isHtml: true, hasHeight: true }); 

Both ways works without each other but they didn't work when I tried to combine them.

Is it possible to do this? Please advise me some ideas and solutions.

2
  • 1
    an idea that you could try, is to create another container, inside or outside... not the best solution though Commented Sep 5, 2016 at 16:40
  • 1
    ng-class is rather simple directive, you can always make your own, that does exactly what you want. Accepts arrays or whatever. Commented Sep 5, 2016 at 16:53

2 Answers 2

3

There is another syntax that looks like this

<div ng-class="[custom1, custom2, {'text-danger': isBadJuJu()}]">Some Text</div> 

Where custom1 and custom2 are variables within the scope of your controller, and the {} is a set of expressions, much like the syntax you are using in your first example

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

Comments

1

It is better to have the ng-class assigned to a variable in the scope. i.e ng-class = customClasses

and in the controller something like this. Doing this makes you have a complete control on what classes must be applied on the modal.

EDIT: Check this sample application in plnkr

$scope.customClasses = { 'is-msg': $scope.message.type == 'msg', 'height-limit': $scope.message.hasHeight, "h-md" : true, "text-info": true }; 

4 Comments

We still have to pre-define the classes, I would like to pass any class I want.
I would like to pass any class I want what does this actually mean ?
Misunderstood, I see what you mean, but I sitll need to use the expressions, they are needed in other parts of the application.
@Nhan Please accept the answer if it solved your case. It can help others too :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.