65
rated 0 times
[
70]
[
5]
/ answers: 1 / hits: 43803
/ 10 Years ago, sat, june 14, 2014, 12:00:00
So, I'm just getting started with angularjs and I'm already confused. I want to change the colour of a list element that corresponds to a hex code colour that is in an array. I've tried some stuff but I just can't get it.
Here's my code so far:
HTML
<div id=mainContentWrap ng-app=newApp>
<div id=personContainer ng-controller=personController>
<ul id=personList>
<li class=bigBox no_s ng-style=personColour ng-repeat=i in persons ng-hover=changeColor()>< href=#/{{i.person_id}}>{{i.person_name}}</a></li>
</ul>
Javascript:
var app=angular.module('newApp',[]);
app.controller('personController',function($scope,$rootScope){
$rootScope.persons=[
{person_id:'0',person_name:'Jim',colour:cc0000},
{person_id:'4',person_name:'Bob',colour:f57900},
{person_id:'2',person_name:'James',colour:4e9a06},
{person_id:'9',person_name:'Paul',colour:3465a4},
{person_id:'3',person_name:'Simon',colour:77507b}
];
$scope.changeColor(){
$scope.personColour=$scope.persons.color// not sure what to do here???
}
});
More From » angularjs