How to Set Background image of div with ng-style

前端 未结 3 1566
离开以前
离开以前 2020-12-02 20:30

Basically i have a link, and when it\'s clicked, i display a modal. Now i can display other properties on the modal like title except the background Image ! urghhh !

3条回答
  •  醉话见心
    2020-12-02 21:09

    Correct syntax for background-image is:

    background-image: url("src");
    

    Correct syntax for ng-style is:

     

    for example :

    JSFiddle : http://jsfiddle.net/U3pVM/7194/

    also You can use custom directive :

    app.directive('backgroundImageDirective', function () {
        return function (scope, element, attrs) {
            element.css({
                'background-image': 'url(' + attrs.backgroundImageDirective + ')',
                'background-repeat': 'no-repeat',
            });
        };
    });
    

    for example :

    JSFiddle : http://jsfiddle.net/U3pVM/7193/

    Update :

    which would not attempt to fetch a non-existing image.

提交回复
热议问题