I have multiple buttons that change a CSS attribute for text color. I am able to get this working using static values such as 'blue' or 'red', but I want to access hex code values which are saved in an object within my controller.
<body ng-app="MyApp" ng-controller="AppCtrl">
<input type="button" value="blue" ng-style="{color: 'blue'}"
ng-click="myColor = { color:'blue' }">
<div ng-repeat="person in people" ng-style="myColor">
Name: {{ person.name }} <br>
Birth Year: {{ person.birth }}<p>
</div>
</body
Here is my controller
var app = angular.module('MyApp', []);
app.controller('AppCtrl', function($scope) {
$scope.colors = [
{ color: 'b1', value: '#000000' }, //black
{ color: 'b2', value: '#000099' }, //blue
{ color: 'r1', value: 'ff0000' }, //red
{ color: 'y1', value: '#ffff00' } //yellow
];
$scope.people = [
{ name: 'Abraham Lincoln', birth: '1809' },
{ name: 'Benjamin Franklin', birth: '1706' },
{ name: 'George Washington', birth: '1732' }
];
})
I want to change
ng-click="myColor = { color:'blue' }"
to something along the lines of
ng-click="myColor = { color:'colors[1].value' }