AngularJS supports .css() jQuery functionality. Here in below examples we can see how to set style to an element.
Angular2 : If you are looking for Angular2 solution, Please click here

Steps to set style to an elemnt :

  1. Get angular element of html element
  2. Use .css() set  style to that element
var myEl = angular.element( document.querySelector( '#divID' ) );
myEl.css('color','red'));

Set style using ng-style

<html ng-app="" ng-controller="myCtrl">
....
<button ng-click="myStyle={color:'red'}">Set Color</button>
<button ng-click="myStyle={'background-color':'blue'}">Set Background color</button>
<button ng-click="myStyle = {}">Set Background color</button>
<div>Click above buttons</div>
<script>
function myCtrl($scope) {
    $scope.myStyle = {};
}
</script>
Try It Your Self

0 comments:

Blogroll

Follow this blog by Email

Popular Posts