An ng-style is a directive to use css style properties and all component is to make design. The design properties is make controller scope object is created and than the object is set to ng-style value.
Syntax:
<div ng-style="expression"></div>
AngularScript:
<div ng-app="colorApp">
<div ng-controller="ColorCtrl">
<input type="button" value="set color" ng-click="demo()">
<span ng-style="myStyle">Sample Text</span>
<pre>myStyle={{myStyle}}</pre>
</div>
</div>
var app = angular.module('colorApp',[]);
app.controller('ColorCtrl', function($scope){
$scope.myStyle = {};
$scope.demo = function(){
$scope.myStyle = {
'color': 'green',
'font-size': '42px',
'font-family': 'Arial,Helvetica Neue,Helvetica,sans-serif'
};
}
});
span {
color: red;
font-size: 12px;
font-family: 'Arial,Helvetica Neue,Helvetica,sans-serif;
}
Result
Demo
Syntax:
<div ng-style="expression"></div>
AngularScript:
<div ng-app="colorApp">
<div ng-controller="ColorCtrl">
<input type="button" value="set color" ng-click="demo()">
<span ng-style="myStyle">Sample Text</span>
<pre>myStyle={{myStyle}}</pre>
</div>
</div>
var app = angular.module('colorApp',[]);
app.controller('ColorCtrl', function($scope){
$scope.myStyle = {};
$scope.demo = function(){
$scope.myStyle = {
'color': 'green',
'font-size': '42px',
'font-family': 'Arial,Helvetica Neue,Helvetica,sans-serif'
};
}
});
span {
color: red;
font-size: 12px;
font-family: 'Arial,Helvetica Neue,Helvetica,sans-serif;
}
Result
Demo
Comments
Post a Comment