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

前端 未结 9 2199
青春惊慌失措
青春惊慌失措 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 06:01

    My solution, using if..else statement. It is always a good practice if you want to avoid unnecessary frustrations, to check that your variable exists and is set. Otherwise, provide a backup image in case; You can also specify multiple style properties, like background-position: center, etc.

提交回复
热议问题