我正在尝试在样式元素中使用角度js绑定,但它似乎不起作用.这是一个错误,还有更好的方法吗?
<style ng-repeat="test in styles">
.test {
background-color: {{ test.backgroundColor }};
display: {{ test.display }};
width: {{ test.width }};
height: {{ test.height }};
}
</style>
Run Code Online (Sandbox Code Playgroud)
我不认为Angular会分析样式元素.您可能想要使用ngStyle指令:
http://docs.angularjs.org/api/angular.module.ng.$compileProvider.directive.ngStyle
<!doctype html>
<html ng-app>
<head>
<script src="http://code.angularjs.org/angular-1.0.0rc10.min.js"></script>
</head>
<body>
<div ng-init="styles=[{backgroundColor: 'red', width:'100px', height: '100px', display: 'block'}]">
<div ng-repeat="test in styles" ng-style="test">
.test {
background-color: {{ test.backgroundColor }};
display: {{ test.display }};
width: {{ test.width }};
height: {{ test.height }};
}
</div>
</html>
Run Code Online (Sandbox Code Playgroud)
Plunker(比如jsFiddle,但更加Angular友好)Demo
| 归档时间: |
|
| 查看次数: |
5833 次 |
| 最近记录: |