更新时间:2022-10-15 20:44:02
您使用Angular 1指令。对于Angular 2,当组件隐藏或绑定到HTML隐藏属性 [hidden]时,不需要在DOM中使用
如果您希望组件始终位于DOM中,但隐藏了CSS。 * ngIf
例如:
< div * ngIf =newTrustFormVisibleclass =panel panel-default>
或
< div [hidden] =!newTrustFormVisibleclass =panel panel-default>
According to my interpretation of the documentation, if I want to be able to have an element hidden by default, and shown when a link is clicked, the following ought to work?
In /app/app.component.ts
newTrustFormVisible: false;
In /app/app.component.html
<a href="#" (click)="newTrustFormVisible = !newTrustFormVisible;">[Add New]</a>
<div ng-show="newTrustFormVisible" class="panel panel-default">
...
</div>
However, this does not work. It also produces no errors. What am I missing?
Your using Angular 1 directives. For Angular 2 use *ngIf
for components that do not need to be in the DOM when they are hidden or bind to the HTML hidden property [hidden]
if you want the component to always be in the DOM but hidden with CSS.
e.g:
<div *ngIf="newTrustFormVisible" class="panel panel-default">
or
<div [hidden]="!newTrustFormVisible" class="panel panel-default">