Angular 引入SVG并动态修改颜色,修改svgIcon颜色!

前提:

https://v10.material.angular.io/components/icon/overview

TS

import {MatIconRegistry} from '@angular/material/icon';
import {DomSanitizer} from '@angular/platform-browser';

	constructor(
		private iconRegistry: MatIconRegistry,
		private ds: DomSanitizer
	){
		iconRegistry.addSvgIcon('thumbs-up', ds.bypassSecurityTrustResourceUrl('assets/img/thumbs-up.svg'));
	}

Html

<mat-icon  svgIcon="thumbs-up" aria-hidden="false"></mat-icon>

如果想要动态修改svgIcon 颜色的话,需要去掉svg fill里的样式
重点: 一定要把svg 里面所有的 fill 改为 none!

<?xml version="1.0" encoding="UTF-8"?>
<svg width="15px" height="15px" viewBox="0 0 15 15" version="1.1" color="white" style="color: currentColor" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
    <!-- Generator: Sketch 57.1 (83088) - https://sketch.com -->
    <title>9B96C6EF-3F47-49EA-BE02-90C775B0FEE1</title>
    <desc>Created with Sketch.</desc>
    <defs>
        <polygon id="path-1" points="0 0.322666667 7.81526667 0.322666667 7.81526667 12.7288667 0 12.7288667"></polygon>
    </defs>
    <g id="页面-1" stroke="none" stroke-width="1" fill="currentColor" fill-rule="evenodd">
        <g id="2.0-柱状-流程图" transform="translate(-12.000000, -114.000000)">
            <g id="仪表盘" transform="translate(12.000000, 114.000000)">
                <path d="M10.9004,8.71163333 C10.5184,10.0149667 9.4364,11.0616333 8.00973333,11.3236333 C7.0554,11.4986333 6.1214,11.2886333 5.36073333,10.8086333 L3.0394,13.6153 C4.6054,14.7479667 6.61306667,15.2656333 8.66406667,14.8889667 C11.6324,14.3439667 13.8524,12.0836333 14.4907333,9.31863333 L10.9004,8.71163333 Z" id="Fill-1" fill="currentColor"></path>
                <path d="M10.9391333,6.7816 C10.9571333,6.8546 10.9771333,6.9266 10.9911333,7.00126667 C11.0148,7.12926667 11.0308,7.25693333 11.0411333,7.3836 L14.6691333,7.99693333 C14.6928,7.45526667 14.6584667,6.9026 14.5568,6.3466 C14.5041333,6.06126667 14.4341333,5.7836 14.3508,5.51226667 L10.9391333,6.7816 Z" id="Fill-3" fill="currentColor"></path>
                <g id="编组" transform="translate(0.000000, 0.010767)">
                    <mask id="mask-2" fill="currentColor">
                        <use xlink:href="#path-1"></use>
                    </mask>
                    <g id="Clip-6"></g>
                    <path d="M4.3776,9.8952 C4.0396,9.44786667 3.79526667,8.91986667 3.68726667,8.33153333 C3.31693333,6.31453333 4.65193333,4.3792 6.66893333,4.0092 C6.84826667,3.9762 7.02626667,3.9612 7.20326667,3.95486667 L7.81526667,0.337533333 C7.22526667,0.299866667 6.6216,0.3322 6.01426667,0.443866667 C2.02826667,1.17553333 -0.609733333,4.99986667 0.1216,8.98586667 C0.390266667,10.4488667 1.07693333,11.7288667 2.0336,12.7288667 L4.3776,9.8952 Z" id="Fill-5" fill="currentColor" ></path>
                </g>
                <path d="M8.52343333,4.15366667 C9.27876667,4.40866667 9.93576667,4.903 10.3917667,5.56233333 L13.8467667,4.27733333 C12.8751,2.41333333 11.1444333,1.06466667 9.13143333,0.556333333 L8.52343333,4.15366667 Z" id="Fill-7" fill="currentColor"></path>
            </g>
        </g>
    </g>
</svg>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值