0

I am trying to add a background image to my ionic app but not able to figure out how.

My codepen is given here

My HTML is given below

<body>
<div ng-controller="ImageController">
<div ng-style="{'background-image':'url({{images}})'}" style="height: 100px"></div>  
</div>

My JS is given below

  angular.module('starter.controllers', [])
  .controller("ImageController", function($scope){
  console.log("Hi there")
  $scope.images= "http://31.media.tumblr.com/bc0ea7c5f95701bff499f78b59d23e68/tumblr_mr74z9Lt3O1rs0z5go1_500.jpg"
});

Expected behavior: the image should span the background entirely.

Current behavior: A blank screen exists instead of the image

lordlabakdas
  • 1,163
  • 5
  • 18
  • 33

2 Answers2

0
app.directive('backImg', function(){
    return function(scope, element, attrs){
        var url = attrs.backImg;
        element.css({
            'background-image': 'url(' + url +')',
            'background-size' : 'cover'
        });
    };
});​

try your own directive

<div back-img="<some-image-url>" ></div>

Look this also, I found solution here: angularjs: ng-src equivalent for background-image:url(...)

Community
  • 1
  • 1
Tam Nguyen
  • 115
  • 1
  • 9
0

Try

<div ng-style="{'background-image':'url('+images+')'}" style="height: 100px"></div>  
Johannes Reuter
  • 3,501
  • 19
  • 20