I'm trying to use angular js bindings within a style element yet it doesn't seem to work. Is this a bug and is there a better way to do this?
<style ng-repeat="test in styles">
.test {
background-color: {{ test.backgroundColor }};
display: {{ test.display }};
width: {{ test.width }};
height: {{ test.height }};
}
</style>
I don't think Angular parses style elements. You probably want to use the ngStyle directive:
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 (like jsFiddle, but more Angular-friendly) Demo
This now works in newer versions of Angular.
Here http://jsfiddle.net/PpyVn/4/ is the OPs fiddle with 1.0 replaced with 1.3.0-rc.3.
<script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.3/angular.min.js"></script>