When using @HostBinding
to bind a property to the background-image of my component, it doesn't work when I specify an image URL.
First example with Angular2 RC-1 :
import {Component, HostBinding} from "@angular/core";
@Component({
selector: 'demo',
template: 'something'
})
export class DemoComponent {
@HostBinding('style.background-image')
backgroundImage = 'url(http://placekitten.com/g/200/300)';
}
When inspecting the DOM, we can find <demo>something</demo>
-> NOT GOOD
Second example :
import {Component, HostBinding} from "@angular/core";
@Component({
selector: 'demo',
template: 'something'
})
export class DemoComponent {
@HostBinding('style.background-image')
backgroundImage = 'none';
}
This time, when inspecting the DOM, we can find <demo style="background-image: none;">something</demo>
-> GOOD
I tried with background
instead of background-image
, it works with a color like "blue"
but still doesn't work with an URL.
I also tried to dynamically change the value later with a setTimeout
inside ngAfterViewInit()
, it works when changing from "none"
to "blue"
, but not with an URL, the value stay "none"
.