【问题标题】:occupy 100% of the space available for <router-outlet>占用 <router-outlet> 可用空间的 100%
【发布时间】:2019-03-31 04:01:23
【问题描述】:

我正在使用 3 个组件:

<menu (setAnimal)='setAnimal($event)' ></menu>
 //principalComponent
<router-outlet (activate)='onActivate($event)'></router-outlet>
<footer></footer>

红色边框组件称为PrincipalComponent (&lt;router-outlet&gt;),它应该具有移除页眉和页脚占用空间后的可用高度。如何使PrincipalComponent 包含可用空间的总高度?

这是我的代码:

https://stackblitz.com/edit/angular-8tgjnk?file=app/principal.component.ts

import { Component, Input } from '@angular/core';

   @Component({
    selector: 'principal',
    template: '<div style="height:100%;border:1px solid red;"> outer- 
     outlet</div>',
     styles: [`h1 { font-family: Lato; }`]
   })

   @Component({
    selector: 'menu',
    template: `<div style='border:1px solid blue; height:100px'>THIS IS THE 
    MENU</div>`,
    styles: [`h1 { font-family: Lato; }`]
  })

 @Component({
  selector: 'footer',
  template: `<div style='border:1px solid green'><h1>THIS IS THE FOOTER 
  </h1> </div>`,
  styles: [`div{position: absolute;bottom: 0;width: 100%;}`]
 })

【问题讨论】:

  • 如果你在里面设置一些组件,我认为你不需要它会自动调整
  • 怎么样???我不明白
  • 路由出口被您在运行时为路由器指定的模块替换,然后路由器将伸展以包含这些模块
  • @jonathanHeindl 那我该怎么办?我不知道。
  • 阅读这个:angular.io/tutorial/toh-pt5 特别是 AddRoutes

标签: angular


【解决方案1】:

您总是可以将路由器插座放在样式化的 div 中。

<menu (setAnimal)='setAnimal($event)' ></menu>
<div class="principal-container">
   <router-outlet></router-outlet>
</div>
<footer></footer>

styles.scss:

.principal-container {
   height: calc(100vh - $footer-height -$header-height);
}

或任何其他您想要设置这些矩形样式的方式。

【讨论】:

猜你喜欢
  • 2020-06-05
  • 1970-01-01
  • 1970-01-01
  • 2018-03-31
  • 2018-08-12
  • 2013-06-18
  • 2022-10-05
  • 1970-01-01
  • 2020-01-19
相关资源
最近更新 更多