所以我使用以下JS将样式更改为Angular 2中的某些元素。当我加载视图时,高度设置为maxHeight = 100,但在几毫秒之后它又恢复为样式样式表。任何人都有任何可能发生的线索可以直接用JS角度改变样式吗?
let projectMatchers = document.getElementsByClassName("th-project-matcher");
let rowMatchers = document.getElementsByClassName("th-row-matcher");
let maxHeight = 100;
rowMatchers[i].style.height = maxHeight + "px";
projectMatchers[i].style.height = maxHeight + "px";
答案 0 :(得分:0)
好的,所以我认为我用javscript应用的样式被change events of angular 2覆盖,所以我用ngStyle将样式直接应用到我的div中,它没有问题:
<div class="my-class" [ngStyle]="matchHeight(i)"></div>
这是matchHeight():
public matchHeight(index: number): string {
return {
height: "250px",
};
}