简体   繁体   English

如何控制angular mat-icon的方向

[英]How to control the orientation of the angular mat-icon

Angular version: v9 Angular 版本:v9

I have a button whose mat-icon is an arrow pointing towards the left.我有一个按钮,其垫子图标是一个指向左侧的箭头。 I would like to know if there is any attribute for the mat-icon element tag to allow me to control the orientation of the arrow so that it points upward instead.我想知道 mat-icon 元素标签是否有任何属性允许我控制箭头的方向,使其指向上方。

For the sake of learning purpose, instead of looking for another icon which achieves what I want, I prefer to learn how to do it via attribute in angular.为了学习的目的,与其寻找另一个实现我想要的图标,我更愿意通过 angular 中的属性学习如何实现。

I search online, but could not find a solution.我在网上搜索,但找不到解决方案。 Hence this question.因此这个问题。 Help appreciated.帮助表示赞赏。 Thanks谢谢

Manage to achieve it by doing this通过这样做设法实现它

<mat-icon style="transform: rotate(90deg)">unfold_more</mat-icon>

I believe you can not achieve this using mat-icon as they are two different icons.我相信您无法使用 mat-icon 实现此目的,因为它们是两个不同的图标。 In case you want to achieve this, you would create the icon yourself using css and maybe add a class that points it upward if it meets a certain flag.如果你想实现这一点,你可以使用 css 自己创建图标,并可能添加一个 class,如果它遇到某个标志则指向上方。

Adding onto @Nick Wills answer, if one wants to further add style conditionally they can do so with the help of ngStyle as follows:添加到@Nick Wills 的答案中,如果有人想有条件地进一步添加样式,他们可以在ngStyle的帮助下进行,如下所示:

<mat-icon [style.transform]="condition ? '':'rotate(180deg)'">chevron_right</mat-icon>

More info at更多信息在

  1. https://angular.io/api/common/NgStyle https://angular.io/api/common/NgStyle
  2. Angular - How to apply [ngStyle] conditions Angular - 如何应用 [ngStyle] 条件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM