I have a question about angularJS.
I would like to use ng-repeart to create a program that changes the background color when I click on an item from the displayed list.This time I want to run the following program using the data binding function of angularJS, but it doesn't work. The list looped with ng-repeart contains multiple keys and values.This time, I would like to have a key called style with a CSS as one of the keys.
HTML File Side
<div ng-repeart="item in list"ng-click="change(item)"ng-style="{{item.style}}">
<P> Item name to display </p>
</div>
JS File Side
$scope.change=function(check){
if(check.style==null){
check.style="{backgroundColor:'red'}";
} else {
check.style="{backgroundColor:'blue'}";
}
}
Currently, the data is bound and the code is changed, but the way it looks remains the same.
How do I deal with this situation?
$scope.$apply(function(){
if(check.style==null){
check.style="{backgroundColor:'red'}";
} else {
check.style="{backgroundColor:'blue'}";
}
});
Will this not work?
© 2024 OneMinuteCode. All rights reserved.