目前在 AngularJS 中存在 JSON 问题,我在其中选择了“img”对象,它控制日志,但不适用于范围。任何人都可以解释一下吗?
'use strict';
angular.module('AppliedSiteApp').controller('CarouselCtrl', function ($scope) {
// CAROUSEL IMAGES
var carouselImages = [
{
"img": "background-image: url('images/carousel/carousel1.jpg')"
},
{
"img": "'background-image': 'url(images/carousel/carousel2.jpg)'"
},
{
"img": "'background-image': 'url(images/carousel/carousel3.jpg)'"
},
{
"img": "'background-image': 'url(images/carousel/carousel4.jpg)'"
},
{
"img": "'background-image': 'url(images/carousel/carousel5.jpg)'"
},
{
"img": "'background-image': 'url(images/carousel/carousel6.jpg)'"
},
{
"img": "'background-image': 'url(images/carousel/carousel7.jpg)'"
},
{
"img": "'background-image': 'url(images/carousel/carousel8.jpg)'"
}
];
// SET INITIAL CAROUSEL IMAGE
$scope.carouselImage = carouselImages[0].img;
console.log('image', $scope.carouselImage);
});
我正在尝试将其应用于范围:
<div class="carousel" ng-style="carouselImage"></div>