【发布时间】:2023-03-06 17:23:01
【问题描述】:
当导航到 '/child' 路由时,我的应用程序的根 <router-outlet></router-outlet> 将在子模块中显示以下组件:
child.component.ts
import {Component} from "@angular/core";
@Component({
template: `
<div style="display:flex; width: 100%; height: 100%;">
<custom-sidebar-component></custom-sidebar-component>
<router-outlet></router-outlet>
</div>`
})
export class ChildComponent {
}
现在这个组件显示得很好,并按我的预期填满了整个屏幕。但是,当我尝试导航到该模块的子路径时,例如“/child/home”,我希望在上面的组件模板中看到的子 <router-outlet></router-outlet> 中显示以下 HTML。
child-home.component.html
<style>
.parent-style {
display: flex;
flex-flow: row wrap;
width: 100%;
height: 100%;
}
.box-style {
display: flex;
justify-content: center;
align-items: center;
flex-grow: 1;
background: red;
color: white;
border: 1px solid black;
}
</style>
<div class="parent-style">
<div class="box-style">Box 1</div>
<div class="box-style">Box 2</div>
</div>
但是这次路由器插座的内容并没有像我希望的那样填满可用空间。我能够看到我想要的结果的唯一方法是打开开发工具并编辑包装我的组件的 Angular 生成的 _nghost 属性。如何让我的组件填满可用空间?
这是我所期望的
这是我实际得到的
【问题讨论】:
标签: angular angular2-routing angular2-template angular-routing angular2-components