gpt4 book ai didi

样式元素中的AngularJS不起作用

转载 作者:行者123 更新时间:2023-12-04 17:54:20 25 4
gpt4 key购买 nike

我正在尝试在样式元素中使用 Angular js 绑定(bind),但它似乎不起作用。这是一个错误,有没有更好的方法来做到这一点?

<style ng-repeat="test in styles">
.test {
background-color: {{ test.backgroundColor }};
display: {{ test.display }};
width: {{ test.width }};
height: {{ test.height }};
}
</style>

http://jsfiddle.net/cmsanche/PpyVn/

最佳答案

我不认为 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>

Plunker(类似于 jsFiddle,但对 Angular 更友好) Demo

关于样式元素中的AngularJS不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10906776/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com