ngStyle对象表达属性angular 2的多个值

时间:2016-11-10 18:18:21

标签: angular

是否可以在ngStyle指令中向属性添加多个值?例如:

<div [ngStyle]='{"background" : ["rgba(248,80,50,1)", "-webkit-gradient(left top, right top, color-stop(0%, rgba(248,80,50,1)), color-stop(50%, rgba(241,111,92,1)), color-stop(51%, rgba(246,41,12,1)), color-stop(71%, rgba(240,47,23,1)), color-stop(100%, rgba(231,56,39,1)))"]}' ></div>

由于

1 个答案:

答案 0 :(得分:1)

在这个例子中你不能只使用自定义类吗?在组件定义中,您可以使用styleUrls为该特定组件包含唯一的样式表。例如:

@Component({
selector: 'my-component',
moduleId: module.id,
templateUrl: 'my-component.html',
styleUrls: ['my-component.css'] // <-- here
})

如果您还需要切换不同的样式,可能更容易使用ngClass