0

I have set ng-class on the div i want to apply css when file is selected so below onSelect i want to change div color to green. How can i achieve this task using AngularJs ?

html

<div class="text-arrow" ng-class="{activeBackground:applyActive}">File Selection<span class="arrow-div"></span></div>

css

.activeBackground{
       background-color: green;
    }

script.js

$scope.onSelect = function (e) {
        $scope.applyActive = true;
}
6
  • 1
    current code should work..is there any console error? Commented Jan 6, 2016 at 15:31
  • there is a typo her ng-class="{activeBackground:applyActive}" it should be ng-class="{'activeBackground':applyActive}" Commented Jan 6, 2016 at 15:32
  • 3
    @AlainIb no..' single qoute will be used only when class name will have special character..it will work without ' too Commented Jan 6, 2016 at 15:33
  • I want to make variable true onSelect but with above answer it looks like it will be true all the scenarios also if i want to add more classes lets say completeBackground and set different color to it how can i do that Commented Jan 6, 2016 at 15:37
  • If i dont need single quote then whats the problem with my code Commented Jan 6, 2016 at 15:39

1 Answer 1

1

Here's a working plnker of what you're trying to achieve.

 <div ng-class="{ activeBackground: applyActive }">File Selection</div>
 <button ng-click="toggleBackground()">Toggle background</button>

Possible issues with your code:

  • you have another style that overwrites the background
  • the onSelect function you mentioned is not invoked properly
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.