I know how to add a class on click of a button in 'jQuery'
$('#button1').click(function(){
$('#div1').addClass('alpha');
});
I want to achieve same thing by angular js. I have a controller - myController1. Can someone help me do it eazily?
I know how to add a class on click of a button in 'jQuery'
I want to achieve same thing by angular js. I have a controller - myController1. Can someone help me do it eazily? |
|||
|
AngularJS has some methods called JQlite so we can use it. see link Select the element in DOM is
add the class like So finally
|
|||
|
You can use HTML
In your controller (to make sure the class is not shown by default)
Now, when you click the button, the $scope.alpha variable is updated and ng-class will add the 'alpha' class to your button. |
|||
|
Try this.. If jQuery is available, angular.element is an alias for the jQuery function.
Ref:https://docs.angularjs.org/api/ng/function/angular.element |
|||||
|
Use the MV* PatternBased on the example you attached, It's better in angular to use the following tools:
for example:
This gives you an easy way to decouple your implementation.
e.g. you don't have any dependency between the |
||||
|
First thing, you should not do any DOM manipulation in controller function. Instead, you should use directives for this purpose. directive's link function is available for those kind of stuff only. AngularJS Docs : Creating a Directive that Manipulates the DOM
change callback can be used as listener for click event. |
|||
|