如下所示:

<!doctype html>
<html lang="en">
<head>
 <  charset="UTF-8">
 <  src="angular.min.js"></ >
</head>
<body>
<div ng-app="module" ng-controller="ctrl">
 颜色: <input type="text" ng-model="color">
 大小: <input type="number" ng-model="size"><br/>
 <!--通过输入color和size的值,改变style的值-->
 <span ng-style="{color:color,fontSize:size+'px'}">泠泠在路上</span>
</div>
< >
 var m = angular.module('module', []);
 m.controller('ctrl', ['$scope', function ($scope) {
 }]);
</ >
</body>
</html>

效果图:

angularJs ng-style动态改变样式

以上这篇对angularJs中ng-style动态改变样式的实例讲解就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。

收藏 打印