Angular Nativescript 可见性默认为 true,即使变量已初始化 [英] Angular Nativescript visibility defaults to true, even when variable is initialized
本文介绍了Angular Nativescript 可见性默认为 true,即使变量已初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在 Nativescript 中默认隐藏"一个元素?
Is there a way to default "hide" an element in Nativescript?
我的组件中有
export class HouseholdContactComponent{
private isLoading = true
}
在我的 xml 中
<StackLayout [visibility]="isLoading ? 'collapse' : 'visible'">
<Label text="Hi there"></Label>
</StackLayout>
使用此代码,屏幕会闪烁您好"消息,然后消失.
With this code, the screen flashes the "Hi there" message and then it goes away.
推荐答案
与其使用 [visibility] 属性,不如使用 Angular *ngIf
指令.
Rather than using the [visibility] property, you should use the Angular *ngIf
directive.
<StackLayout *ngIf="!isLoading">
<Label text="Hi there"></Label>
</StackLayout>
附带说明,为了绑定到一个属性属性并将其绑定到 Angular 正在做的插值,您需要在它前面加上 attr
,例如您需要编写 [attr.visibility]
而不仅仅是 [visibility]
.
On a side note, in order to bind to a attribute property and bind it to interpolation Angular is doing you need to prefix it with attr
, for example you would need to write [attr.visibility]
rather than just [visibility]
.
这篇关于Angular Nativescript 可见性默认为 true,即使变量已初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文