我有一個標籤導航元素有兩個選項卡,它需要顯示一個基於哪個選項卡被點擊並隱藏其他組件的組件。如果點擊的選項卡已經「激活」,則該組件需要保持顯示。切換兩個元素之間的顯示和隱藏
我有這個工作,但它似乎對我非常低效。任何人都可以告訴我一個更好的方法來做到這一點
下面是我現在設置的方法。爲了不在問題中發佈每個文件,請了解該項目的設置是否正確。
@Component({
selector: 'my-app',
template: `
<div>
<button type="button" (click)="changeShowStatus(oneShowing=true,twoShowing=false)">1</button>
<button type="button" (click)="changeShowStatus(twoShowing=true,oneShowing=false)">2</button>
<div class="box1" *ngIf="oneShowing">
<p>some content</p>
</div>
<div class="box2" *ngIf="twoShowing">
<p>some content2</p>
</div>
</div>
`,
})
export class App {
name:string;
oneShowing:boolean;
twoShowing:boolean
constructor() {
this.oneShowing = true;
this.twoShowing = false
}
}