javascript - Change background image on hover with AngularJS -
i have scope of 's background images, can't figure out how make them change. tried several variants, none of them has passed. here's code:
<div ng-controller="maincontroller" class="main"> <div ng-repeat="land in lands" class="col-md-9" ng-style="{ 'background-image': 'url({{ land.cover }})'}"> <p>{{ land.name }}</p> </div> </div>
javascript:
app.controller('maincontroller', ['$scope', function($scope) { $scope.lands = [ { cover: 'img/norway.jpg', cover1: 'img/norway1.jpg', name: 'norway' }, { cover: 'img/sweden.jpg', cover1: 'img/sweden1.jpg', name: 'sweden' }, { cover: 'img/denmark.jpg', name: 'danmark' }, { cover: 'img/iceland.jpg', name: 'iceland', }, { cover: 'img/finland.jpg', name: 'finland' }, { cover: 'img/estonia.jpg', name: 'estonia' } ]; }]);
you can't use interpolation tags in expression context. should be:
<div ng-controller="maincontroller" class="main"> <div ng-repeat="land in lands" class="col-md-9" ng-init="coverimage = land.cover" ng-mouseover="coverimage = land.cover" ng-mouseout="coverimage = land.cover1" ng-style="{ 'background-image': 'url(' + coverimage + ')' }"> <p>{{ land.name }}</p> </div> </div>
Comments
Post a Comment