【发布时间】:2018-02-09 17:15:42
【问题描述】:
我有一个名为 HomeComponent 的组件。因为我需要根据条件显示多个组件。
我的功能在一个页面中调用不同的页面,进入 Home 组件。我正在使用 *ngIf 来显示隐藏 div(我当前的逻辑是否在我的大脑中运行 :-( )。这样我就遇到了一个问题。当我点击 component mars 时,我必须显示组成冥王星,所以一个。
home.component.html
<ion-home>
<ion-content *ngIf="mars==true">
<component-mars>
//consider this as the code inside the component plz
<button (click)="gotoPluto()">component mars</button>
</component-mars>
</ion-content>
<ion-content *ngIf="pluto==false">
<component-pluto>
//consider this as the code inside the component plz
<button (click)="gotoEarth()">component mars</button>
</component-pluto>
</ion-content>
</ion-home>
mars.component.ts
gotoPluto(){
mars= false; // so the mars should hide
pluto=false; //so the pluto will hide and show earth
}
我的家庭组件如何检测到这一点。我尝试使用 ion-tabs navController 但它有 tab-bar 。我已经在指定组件中有我的按钮。
【问题讨论】:
-
使用ngSwitch怎么样?
-
嗨,我发现并回答了它工作正常。那是使用 Events 。我能够查看不同的视图。我正在使用相同的 *ngIf 条件。我可以使用事件 emmit 引用 link 更改条件。但问题是我必须像使用 navCtrl.push 之前那样传递数据。目前对于我的解决方案,我正在使用本地存储
标签: javascript reactjs typescript ionic-framework angular2-routing