在 Angular 中嵌套项目的最佳方式是什么
What is a best way to have nested project in Angular
在不需要生成两个不同的 angular 项目的情况下,将我的网站拆分为两种不同方式的最佳方法是什么?
- 网站申请
- 管理员Area/CMS页面
例如 www.mywebsiteurl.com is official website while www.mywebsiteurl.com/admin 用于管理 Web 内容。
目前我有这个
我不希望页眉、菜单和页脚组件出现在任何管理页面上,我该如何实现?
在每个非管理路由中包含页眉、菜单和页脚,并且不在管理路由中包含它们。
就这么简单:)
编辑:由于建议的修复太长而无法实施,您可以在主组件中订阅 ActiveRoute
。在路线上,您可以将 true 或 false 分配给布尔值,比方说 admin
.
然后使用 ng-if
删除当此变量为 false 或 true 时不需要的元素。
来自你的监护人的@mikegross 这就是我解决它的方法。非常感谢
disableComponent = false;
constructor(location: Location, router: Router) {
router.events.subscribe((val) => {
if(location.path() != '/admin'){
this.disableComponent = true;
}else{
this.disableComponent=false;
}
});
}
<app-header *ngIf='disableComponent'></app-header>
<app-site-menu *ngIf='disableComponent'></app-site-menu>
<router-outlet></router-outlet>
<app-footer *ngIf='disableComponent'></app-footer>
在不需要生成两个不同的 angular 项目的情况下,将我的网站拆分为两种不同方式的最佳方法是什么?
- 网站申请
- 管理员Area/CMS页面
例如 www.mywebsiteurl.com is official website while www.mywebsiteurl.com/admin 用于管理 Web 内容。
目前我有这个
我不希望页眉、菜单和页脚组件出现在任何管理页面上,我该如何实现?
在每个非管理路由中包含页眉、菜单和页脚,并且不在管理路由中包含它们。
就这么简单:)
编辑:由于建议的修复太长而无法实施,您可以在主组件中订阅 ActiveRoute
。在路线上,您可以将 true 或 false 分配给布尔值,比方说 admin
.
然后使用 ng-if
删除当此变量为 false 或 true 时不需要的元素。
来自你的监护人的@mikegross 这就是我解决它的方法。非常感谢
disableComponent = false;
constructor(location: Location, router: Router) {
router.events.subscribe((val) => {
if(location.path() != '/admin'){
this.disableComponent = true;
}else{
this.disableComponent=false;
}
});
}
<app-header *ngIf='disableComponent'></app-header>
<app-site-menu *ngIf='disableComponent'></app-site-menu>
<router-outlet></router-outlet>
<app-footer *ngIf='disableComponent'></app-footer>