AngularJS- ng-style
richtlijn
Voorbeeld
Voeg 'n bietjie styl by met AngularJS deur 'n voorwerp met CSS-sleutels en waardes te gebruik:
<body ng-app="myApp" ng-controller="myCtrl">
<h1 ng-style="myObj">Welcome</h1>
<script>
var app = angular.module("myApp", []);
app.controller("myCtrl",
function($scope) {
$scope.myObj = {
"color" : "white",
"background-color" : "coral",
"font-size" : "60px",
"padding" : "50px"
}
});
</script>
</body>
Definisie en gebruik
Die ng-style
richtlijn spesifiseer die stylkenmerk vir die HTML-element.
Die waarde van die ng-style
eienskap moet 'n voorwerp wees, of 'n uitdrukking wat 'n voorwerp terugstuur.
Die objek bestaan uit CSS-eienskappe en -waardes, in sleutelwaardepare.
Sintaksis
<element ng-style="expression"></element>
Ondersteun deur alle HTML-elemente.
Parameterwaardes
Value | Description |
---|---|
expression | An expression which returns an object where the keys are CSS properties, and the values are CSS values. |