Attribute property binding for background-image url in Angular 2

前端 未结 4 477
臣服心动
臣服心动 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:16

    The main reason is simple, you declared a global variable as blankImage but in the template you called image instead of blankImage.

    Your ts code variable blankImage

    blankImage: string = '../assets/.../camera.png';
    

    Your template code variable image

提交回复
热议问题