【发布时间】:2018-07-26 15:10:17
【问题描述】:
我有一个 component.html 可以嵌入我的 svg 组件:
<masterflex-sidebar>
<masterflex-logo sidebar-logo color="white">
</masterflex-logo>
</masterflex-sidebar>
我的logo.ts 文件:
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'masterflex-logo',
templateUrl: './masterflex.component.html',
styleUrls: ['./masterflex.component.scss']
})
export class MasterflexComponent implements OnInit {
@Input() color:string
constructor() { }
ngOnInit() {
}
}
我的 svg 组件(部分):
<svg
version="1.1"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
x="0px" y="0px"
viewBox="0 0 237.4 35.9"
height="35.9"
width="237.4"
xml:space="preserve" *ngIf="color">
我希望能够将我的 svg 组件的颜色更改为我想要的任何颜色(在我的第一个组件中使用 color="white" 设置)并将该颜色应用于我的 svg。有没有办法将该颜色属性传递给 scss 样式?
【问题讨论】:
-
“将颜色属性传递给 scss 样式”是什么意思?您可以使用属性绑定来设置 SVG 元素的颜色。这对你有用吗?
-
@ConnorsFan 那行得通,我只是在想怎么做,但还没弄明白