How to add background-image using ngStyle (angular2)?

前端 未结 9 2232
青春惊慌失措
青春惊慌失措 2020-11-28 05:36

How to use ngStyle to add background-image? My code doesn\'t work:

this.photo = \'http://dl27.fotosklad.org.ua/20121020/6d0d7b1596285466e8bb06114a88c903.jpg\         


        
9条回答
  •  心在旅途
    2020-11-28 05:45

    Mostly the image is not displayed because you URL contains spaces. In your case you almost did everything correct. Except one thing - you have not added single quotes like you do if you specify background-image in css I.e.

    .bg-img {                \/          \/
        background-image: url('http://...');
    }
    

    To do so escape quot character in HTML via \'

                                              \/                                  \/
    

提交回复
热议问题