Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding background image with 'ng-style' in AngularJS

Tags:

angularjs

I seem unable to use a controller to set the CSS background property of a div. Here is my code so far, as per the documentation:

HTML:

<div class="hero" ng-controller="HeroCtrl" ng-style="heroImage"></div>

JS:

'use strict';

angular.module('AppliedSiteApp').controller('HeroCtrl', function ($scope) {

    $scope.heroImage = {
        background: 'images/brick.jpg'
    };

    console.log($scope.heroImage);

});

CSS:

.hero {
    width: 100%;
    min-height: 350px;
    background-position: center center;
}

I have also tried to replicate this setup in a Fiddle here. Does anyone have any ideas?

like image 773
JohnRobertPett Avatar asked Aug 28 '13 10:08

JohnRobertPett


1 Answers

$scope.heroImage = {
    background: 'url(images/brick.jpg)'
};

background-image requires url() to work.

like image 197
Umur Kontacı Avatar answered Oct 15 '22 11:10

Umur Kontacı