我试图为我的Angular 项目编写一个背景颜色变换器。这是html代码:
<h1>Background color changer</h1>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js"></script>
<script>
var app=angular.module("Myapp",[])
app.controller("Mycontroller", function($scope)
{
$scope.colors=[
{name: 'Red',color:'red'},
{name: 'Yellow',color:'yellow'},
{name: 'Pink',color:'pink'},
{name: 'Cyan',color:'cyan'},
{name: 'Orange',color:'orange'}
]
});
</script>
</head>
<body>
<div ng-app="Myapp" ng-controller="Mycontroller">
<select>
<option value="" selected hidden>Select Color</option>
<option ng-repeat="colorselect in colors"
style="background-color:{colorselect.color}">(colorselect.name)</option>
</select>
<p>
<a routerLink="/loggedinsettings">Go back</a>
</p>
<hr/>
</div>
</body>
</html>
它应该允许您选择一种颜色,然后将该颜色应用为背景。现在,它看起来像这样:图片
有什么想法吗?谢谢
1条答案
按热度按时间b4lqfgs41#
你很接近。只需要使用插值从范围中检索值。