根据我对文档的解释,如果我希望能够默认隐藏一个元素,并在单击链接时显示该元素,那么以下应该可以工作吗?
-
在 /app/app.component.ts 中
newTrustFormVisible: false;
-
在/app/app.component.html中
<a href="#" (click)="newTrustFormVisible = !newTrustFormVisible;">[Add New]</a>
<div ng-show="newTrustFormVisible" class="panel panel-default">
...
</div>
然而,这是行不通的。它也不会产生任何错误。我缺少什么?
您使用 Angular 1 指令。对于 Angular 2 使用*ngIf
对于隐藏或绑定到 HTML 隐藏属性时不需要位于 DOM 中的组件[hidden]
如果您希望组件始终位于 DOM 中但被 CSS 隐藏。
e.g:
<div *ngIf="newTrustFormVisible" class="panel panel-default">
or
<div [hidden]="!newTrustFormVisible" class="panel panel-default">
Angular 1 到 Angular 2 参考 https://angular.io/docs/ts/latest/cookbook/ajs-quick-reference.html
*ngIf https://angular.io/docs/ts/latest/guide/displaying-data.html#!#ngIf
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)