【问题标题】:ngStyle directive not applied to a link tagngStyle 指令未应用于链接标签
【发布时间】:2020-08-25 00:57:57
【问题描述】:

我正在尝试设置从 API 生成的颜色链接的样式。这适用于文本按钮等,但是当我尝试将其应用于链接时它不起作用。

<a href="#" [ngStyle]="{'color': brand?.colours.secondary}" *ngIf="!visitorName" (click)="setVisitor()">Don't want to give your name? That's fine! Start the review!</a>

它只是被引导链接样式覆盖。

将其应用于“p”标签也可以正常工作 - 因此从 API 中提取正确的颜色代码并正常加载:

<p class="mt-5" [ngStyle]="{'color': brand?.colours.secondary}">Don't worry we won't use your details for anything other then to give you the best experience possible.</p>

【问题讨论】:

标签: angular ng-style


【解决方案1】:

使用 attr.style 代替 ngstyle

在 SomeComponent.ts 中

myColor = fetchColorSomehow(); //#ff55aa or any color

在 SomeComponent.html 中

[attr.style]="'color:'+mycolor+'!important'"

这里我们使用 !important

覆盖引导颜色

【讨论】:

    猜你喜欢
    • 2021-01-23
    • 1970-01-01
    • 2014-07-24
    • 2018-08-28
    • 1970-01-01
    • 1970-01-01
    • 2015-08-26
    • 2021-12-21
    • 2017-02-22
    相关资源
    最近更新 更多