typescript – Angular2 @HostBinding无法绑定背景图像样式

前端之家收集整理的这篇文章主要介绍了typescript – Angular2 @HostBinding无法绑定背景图像样式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > 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(修复)

猜你在找的Angularjs相关文章