【发布时间】:2019-01-08 06:27:00
【问题描述】:
我有一个带有 3 个锚标记的导航栏。单击锚标记时,与其关联的某些组件是可见的;而与其他锚标记关联的组件被隐藏。 (即一次只有一个处于活动状态)我的问题是组件仅在您单击导航栏中的项目时才会显示。 ((点击)="...") 有没有办法在页面加载时初始化 a='Y' ? (不使用 JavaScript)
<nav>
<ul>
<li><a href="#" (click)="a='Y'; b='N'; c='N'">Title a</a></li>
<li><a href="#" (click)="a='N'; b='Y'; c='N'">Title b</a></li>
<li><a href="#" (click)="a='N'; b='N'; c='Y'">Title c</a></li>
</ul>
</nav>
<ng-container *ngIf = "a==='Y'"> {some of a's components here....} </ng-container>
<ng-container *ngIf = "b==='Y'"> {some of b's components here....} </ng-container>
<ng-container *ngIf = "c==='Y'"> {some of c's components here....} </ng-container>
【问题讨论】:
-
你试过
ngOnInit吗?
标签: html angular angular5 frontend