Prev Demo
AngularJS
>
CSS Style
Next Demo
Write code here
J
|
B
|
A
<!DOCTYPE html> <html> <head> <title>Demo</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script> </head> <body> <h1>Demo of ng-style directive</h1> <script> var app = angular.module("app", []); app.controller("StyleController", function ($scope) { $scope.CustomStyle = {}; $scope.BColor = "Yellow"; $scope.Color = "Blue"; $scope.SetStyle = function () { $scope.CustomStyle = { 'background-color': $scope.BColor, 'color' : $scope.Color }; } }); </script> <div ng-app="app" ng-controller="StyleController"> Select background: <select ng-model="BColor" ng-change="SetStyle()"> <option>Red</option> <option>Green</option> <option>Blue</option> <option>Yellow</option> </select> Select text color: <select ng-model="Color"> <option>Red</option> <option>Green</option> <option>Blue</option> <option>Yellow</option> </select> <button ng-click="SetStyle()">Set</button> <hr /> <span ng-style="CustomStyle">TechFunda.com</span> </div> </body> </html>
Note: We DO NOT save your trial code in our database.
Output