Attribute property binding for background-image url in Angular 2

前端 未结 4 464
臣服心动
臣服心动 2020-12-05 06:38

I have been struggling to figure out the best way to dynamically change the background-image attribute in a number of Angular 2 components.

4条回答
  •  有刺的猬
    2020-12-05 07:06

    You don't need to use NgStyle. You can also do this:

    [style.background-image]="'url(' + image + ')'"

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

提交回复
热议问题