How to combine ng-class with ng-style?
The style attribute is set using ng-style. The value of ng-style is an object, which is used to refer to CSS style, which is applied to the element.
Syntax:
<element ng-style="object">..</element>
Properties:
Object: Object is used to return css style applied to the element.
Return Value: It returns the style applied to the ng-class elements.
Example 1:
<!DOCTYPE html> <html> <script src= </script> <body ng-app="gfg" ng-controller="geekctrl"> <h1 ng-style="geekstyle"> GeeksforGeeks </h1> <script> var app = angular.module("gfg", []); app.controller( "geekctrl", function($scope) { $scope.geekstyle = { "color": "white", "background-color": "green", "font-size": "80px", } }); </script> </body> </html> |
Output:

Example 2:
<!DOCTYPE html> <html> <script src= </script> <body ng-app="gfg" ng-controller="geekctrl"> <h1 ng-style="geekstyle"> GeeksforGeeks </h1> <h2 ng-style="geekstyle1"> GeeksforGeeks </h2> <script> var app = angular.module("gfg", []); app.controller("geekctrl", function($scope) { $scope.geekstyle = { "color": "white", "background-color": "green", "font-size": "60px", } $scope.geekstyle1 = { "color": "white", "background-color": "green", "font-size": "80px", } }); </script> </body> </html> |
Output:

Browser Support: Listed browsers support ng-class with ng-style–
- Internet Explorer
- Firefox
- Google Chrome
- Opera
- Safari
Recommended Posts:
- Create a Hoverable Side Navigation with HTML, CSS and JavaScript
- JavaScript Interview Questions and Answers | Set 3
- Create a Mobile Toggle Navigation Menu using HTML, CSS and JavaScript
- How to execute AngularJS controller function on page load ?
- How to use Explode effect in jQuery ?
- What is the purpose of "role" attribute in HTML ?
- Difference between console.dir and console.log
- How to universally parse JSON into blocks using jQuery ?
- How to use dynamic variable names in JavaScript ?
- How to bind 'touchstart' and 'click' events but not respond to both ?
- CSS | scrollbar-width Property
- HTML5 | MathML <mtr> Tag
- if/else condition in CSS
- HTML5 | MathML <mth> Tag
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



