[英]How to use a different “template” on Ionic/Angular
I've one ionic app with the menu on the left.我有一个带有左侧菜单的离子应用程序。
The app.component.html has the ion-router-outlet
and all the menu: app.component.html 有
ion-router-outlet
和所有菜单:
<ion-app>
<ion-split-pane contentId="main-content">
<ion-menu contentId="main-content" type="overlay">
<ion-content>
<!-- Profile part -->
<div class="ion-text-center">
<div *ngIf="isLoggedIn$ | async" class="ion-text-center">
<img
ngxGravatar
[email]="email$ | async"
fallback="mp"
size="80"
/>
<ion-button (click)="doLogout()" color="danger">
Logout
</ion-button>
</div>
<div *ngIf="(isLoggedIn$ | async) === false">
<ion-button (click)="doLogin()" color="success">Login</ion-button>
</div>
</div>
<ion-list id="labels-list">
<ion-list-header>Labels</ion-list-header>
<ion-item *ngFor="let label of labels" lines="none">
<ion-icon
slot="start"
ios="bookmark-outline"
md="bookmark-sharp"
></ion-icon>
<ion-label>{{ label }}</ion-label>
</ion-item>
</ion-list>
</ion-content>
</ion-menu>
<ion-router-outlet id="main-content"></ion-router-outlet>
</ion-split-pane>
</ion-app>
I would like to know if it's possible to use a totally different template for some routes ?我想知道是否可以对某些路线使用完全不同的模板? By example, if I've a sign in/sign up page, I don't want to have any menu.
例如,如果我有一个登录/注册页面,我不想有任何菜单。
The menu is one example, but I could imagine a lot of different scenarios, with totally different layouts.菜单只是一个例子,但我可以想象很多不同的场景,有着完全不同的布局。
How to do this?这该怎么做? I could put some *ngIf in the base template, but I will make a lot of them.
我可以在基本模板中放一些 *ngIf,但我会制作很多。
You have a event on ion-router-outlet ie activate which will let you know which component is loaded in router outlet.您在 ion-router-outlet 上有一个事件,即 activate ,它会让您知道路由器出口中加载了哪个组件。 You can use it like :-
你可以像这样使用它:-
HTML HTML
<ion-router-outlet id="main-content" (activate) = "changeTemplate($event)"></ion-router-outlet>
TS:- TS:-
hideMenu=false;
changeTemplate(component: any) {
if(component instanceof SigninPage) {
this.hideMenu = true;
}
}
Use flags like hideMenu in your template with ngIf.使用 ngIf 在模板中使用像 hideMenu 这样的标志。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.