参见英文答案 >
In RC.1 some styles can’t be added using binding syntax 1个
使用
使用
@HostBinding
将属性绑定到组件的背景图像时,在指定图像URL时它不起作用.
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)'; }@H_404_15@在检查DOM时,我们可以找到< demo>的东西< / demo> – >不好
第二个例子:
import {Component,template: 'something' }) export class DemoComponent { @HostBinding('style.background-image') backgroundImage = 'none'; }@H_404_15@这一次,在检查DOM时,我们可以找到< demo style =“background-image:none;”> something< / demo> – >好
我尝试使用背景而不是背景图像,它使用的颜色类似于“蓝色”,但仍然无法使用URL.
我还尝试使用ngAfterViewInit()中的setTimeout动态更改值,当从“none”更改为“blue”时它起作用,但不是使用URL,值保持“none”.
解决方法
这是一种行为,因为Angular2的风格消毒剂非常严格……似乎最近已经修复了.
看到这个问题:
> https://github.com/angular/angular/issues/8491
> https://github.com/angular/angular/issues/8514(修复)