【发布时间】:2017-04-09 18:13:25
【问题描述】:
在 Ionic2 组件中,我使用 HTML 模板中的 [hidden] 指令。 @Component 定义为:
@Component({
selector: 'login-button',
template:
`<button ion-button round (click)="openLogin()" [hidden]="loggedIn">
Login
<ion-icon name="arrow-up"></ion-icon>
</button>
<button ion-button icon-only menuToggle [hidden]="!loggedIn">
<ion-icon name="menu"></ion-icon>
</button>
`
})
我声明了一个组件变量:
export class LoginButton {
loggedIn: boolean = false;
[hidden]="loggedIn" 正在工作。无论登录变量的值如何,[hidden]="!loggedIn" 都会显示按钮。
我该怎么写?
【问题讨论】:
-
我只想补充一点,当需要表演时,使用
*ngIf而不是hidden似乎是个好习惯:"the fastest code is code that is not run and the fastest DOM is DOM that doesn’t exist"(Angular2 官方参考here)。跨度>
标签: html components ionic2 hidden