如何动态地从组件添加样式到body

时间:2017-06-19 11:40:38

标签: angular typescript

如果有按钮,我想在点击时从组件中动态添加.//*[contains(@name,'Category One')] style="overflow:hidden"。 点击此body <a>即可,此时应将isWriteEmail添加到正文

overflow:hidden

尝试了这个 <a href="javascript:void(0)" class="mail-ac-ico" (click)="appComponent.isWriteEmail = true;" data-toggle="tooltip" tooltip="Compose" title="Compose"> <img src="assets/images/icons/icon-open-email.png" alt="email icon"> </a> 无效

1 个答案:

答案 0 :(得分:0)

你必须创建一个类:

.overflowHidden {
    overflow: hidden
}

然后,在模板中:

<a href="javascript:void(0)"
    class="mail-ac-ico"
    (click)="appComponent.isWriteEmail = true;"
    [class.overflowHidden]="appComponent.isWriteEmail"
    data-toggle="tooltip"
    tooltip="Compose"
    title="Compose">
    <img src="assets/images/icons/icon-open-email.png" alt="email icon">
</a>