0

I have a scenario where when click i am changing the border color from black to red by append a class to a div using ng-class.

But when i click a button the modal is getting triggered but the class is not getting appended.

<div ng-class="{'addBorder':clicked}" class="beforeClicked">
<button ng-click="clickToOpen()">My Modal</button>
</div>

function MyCtrl($scope, ngDialog) {
$scope.clicked=false;
$scope.clickToOpen = function () {
        $scope.clicked=true;
    ngDialog.open({ template: 'templateId' });
};

}

.addBorder{
  border:1px solid red;

}
.beforeClicked{
 width:100px;
  height:300px;
  border:1px solid black
}

DEMO

Here the div is already in black border when click on button i am making the flag true which should add class addBorder to the div which appends red color border.

But it isn't happening.

Any help would be appreciated.

3 Answers 3

1

Currently, beforeClicked border properties are overriding the border of .addBorder.

Just interchange the order of your css styles for .addBorder to have more preference.

.beforeClicked {
  width: 100px;
  height: 300px;
  border: 1px solid black
}

.addBorder {
  border: 1px solid red;
}

Updated fiddle: http://jsfiddle.net/nashcheez/mb6o4yd1/700/

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

Comments

0

just make the style !important

.addBorder{
  border:1px solid red !important;      
}

demo

Comments

0

Update your css like below

.beforeClicked{
 width:100px;
  height:300px;
  border:1px solid black
}

.addBorder{
  border:1px solid red;

}

add border class after before clicked class.

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.