First check whether image exists or not then load the image. This type of implementation gives clean UI view to user. In this example, initially we are loading image then assigning as background image if it exists.

Markup

<div id="divID" ng-click="setBackgroundImage($event,'http://lh3.googleusercontent.com/-GRRunt52GXo/AAAAAAAAAAI/AAAAAAAAAH4/Bz2Nf2zrXJk/s512-c/photo.jpg')">
 Sample DIV 1
</div>

Script

$scope.setBackgroundImage = function($event, imgLocation) {
    console.log('setBackgroundImage');
    var bgImg = new Image();
    bgImg.onload = function() {
        var myDiv = $event.target;
        myDiv.style.backgroundImage = 'url(' + bgImg.src + ')';
    };
    bgImg.src = imgLocation;
}

4 comments:

  1. Personally I think overjoyed I discovered the blogs.
    I would recommend my profile is important to me, I invite you to discuss this topic...
    background check mumbai

    ReplyDelete
  2. All things considered, there are a couple of highlights you ought to consider about eCommerce destinations. Above all else, it spares time and work. Product Photography Retouching

    ReplyDelete
  3. It is the fundamental background check approach of American Acme Corporation that all new Staff and indicated new Hourly workers have certain accreditations and criminal and other background data confirmed as a state of business.globe news wire

    ReplyDelete
  4. I am a new user of this site so here i saw multiple articles and posts posted by this site,I curious more interest in some of them hope you will give more information on this topics in your next articles. What day is tommorow

    ReplyDelete

Blogroll

Follow this blog by Email

Popular Posts