我如何在打字稿中为角度5设置zindex

时间:2018-07-23 10:08:39

标签: angular angular5

我正在尝试使用打字稿为课程设置Mymodel.objects.filter(pickup_station_id==drop_station_id) Mymodel.objects.filter(pickup_station_id!=drop_station_id) 。但这是行不通的。如果您有任何想法,请与我分享。

zindex

3 个答案:

答案 0 :(得分:4)

您可以使用NgStyle指令来设置zindex

[ngStyle]="{'z-index':condition ? 9 : 0 }"

答案 1 :(得分:2)

根据情况,使用内联样式绑定可能比使用querySelector更好-

<p [style.z-index]="1">
  Some text
</p>

答案 2 :(得分:-1)

您可以使用NgClass指令,而不要操纵DOM

在您的CSS / Scss文件中:

.class1 {
  z-index: -1;
}

.class2 {
   z-index: 1;
}

在您的TS文件中:

YourBooleanVariableNameHere : boolean;
ngOnInit() {
    this.YourBooleanVariableNameHere = true;
}

在您的HTML文件中:

如果您的条件得到满足:

<some-element [ngClass]="{'class1 class2' : YourBooleanVariableNameHere }">...</some-element>

如果不满足您的条件:请注意,其中包含!符号和变量

<some-element [ngClass]="{'class1' : !YourBooleanVariableNameHere }">...</some-element>

阅读Usage Notes了解更多示例。有关更多方法,请参考here

或者您也可以尝试相同的方法不推荐!

更新:

ngOnInit() {
    document.getElementsByClassName("pagemode")[0].style.zIndex = 1;
}

Working example available here