加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

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

发布时间:2020-12-17 17:26:24 所属栏目:安全 来源:网络整理
导读:参见英文答案 In RC.1 some styles can’t be added using binding syntax????????????????????????????????????1个 使用 @HostBinding 将属性绑定到组件的背景图像时,在指定图像URL时它不起作用. Angular2 RC-1的第一个例子: import {Component,HostBindin
参见英文答案 > 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)';
}

在检查DOM时,我们可以找到< demo>的东西< / demo> – >不好

第二个例子:

import {Component,template: 'something'
})
export class DemoComponent {

    @HostBinding('style.background-image')
    backgroundImage = 'none';
}

这一次,在检查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(修复)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读