[英]How to do overflow-y on an <router-outlet> in angular?
Im new to bootstrap and angular, so I don't know where i went wrong...我是引导程序和 angular 的新手,所以我不知道我哪里出错了......
Situation as it is:现状:
First I use an router-outlet to display a login-page or the "workspace".首先,我使用路由器插座来显示登录页面或“工作区”。
<app-header ></app-header>
<router-outlet></router-outlet>
inside the "workspace":在“工作区”内:
<div class="d-flex flex-row" >
<app-side-navigation> </app-side-navigation>
<div #needOverflow class=" m-0 overflow-auto" >
<router-outlet></router-outlet>
</div>
</div>
the second router-outlet contains a component that needs the overflow-y: auto第二个路由器出口包含一个需要溢出-y的组件:自动
overflow-auto of boodstrap doesnt work!引导程序的溢出自动不起作用!
How the application looks应用程序的外观
If I say that my height of the div#needsOverflow equals to 600px, then I see an overflow that doesnt go to the end of my screen.如果我说我的 div#needsOverflow 的高度等于 600 像素,那么我看到的溢出不会 go 到我的屏幕末尾。 How do I make the overflow go over my whole screen?如何在整个屏幕上溢出 go? I tried height = 100vh but this is to big due my header.我尝试了 height = 100vh 但这很大,因为我的 header。
So I want that my 2nd router-outlet has an overflow-y only when the content of my router outlet leaves the screen, In other words, its also ok that my side-nav & header stay in place所以我希望我的第二个路由器插座只有在我的路由器插座的内容离开屏幕时才有溢出-y,换句话说,我的侧导航和 header 保持原位也可以
I also tried mat-sidenav, but that gives me alot of probs because of the header I think我也尝试过 mat-sidenav,但这给了我很多问题,因为我认为 header
Soooo I fixed this whole story by adding a directive: : Soooo 我通过添加指令修复了整个故事::
app-component html:应用程序组件 html:
<app-header viewportheight></app-header>
<div>
<router-outlet></router-outlet>
</div>
viewportheight.directive: viewportheight.directive:
@Directive({
selector: '[viewportheight]'
})
export class ViewportheightDirective implements AfterViewChecked {
constructor(private el: ElementRef ,private viewportHeight: ViewportheightService) { }
ngAfterViewChecked(): void {
this.sendSizeToService();
}
@HostListener('window:resize')
onResize(){
this.sendSizeToService();
}
sendSizeToService(){
this.viewportHeight.headerheight.next(this.el.nativeElement.offsetHeight)
}
}
workspace.html:工作区.html:
<div class="d-flex flex-row " >
<app-side-navigation class="align-self-start"> </app-side-navigation>
<div class="overflow-auto p-3 w-100" [ngStyle]="{'height': 'calc(100vh - ' + height + 'px)'}">
<router-outlet></router-outlet>
</div>
</div>
With height
being subscribed to a BehavourSubject in my viewportheightService.在我的 viewportheightService 中订阅了一个 BehavourSubject 的height
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.