即使已初始化变量,Angular Nativescript可见性也默认为true [英] Angular Nativescript visibility defaults to true, even when variable is initialized
问题描述
有没有一种方法可以默认隐藏" 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>
使用此代码,屏幕闪烁"Hi there"消息,然后消失.
With this code, the screen flashes the "Hi there" message and then it goes away.
推荐答案
应该使用Angular * ngIf
指令,而不是使用[visibility]属性.
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屋!