Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular router-outlet child can't fill space

I have a problem with filling all available space with the router-outlet.

I use angular/flex-layout for my application. And the component loaded with the router doesn't take all available place.

<div fxLayout="column" fxFlexFill>
  <maat-top-bar></maat-top-bar>
  <router-outlet fxFlex></router-outlet>
</div>

Screenshot of app & dom

The router-outlet take space instead of child component. On screenshot the component is <maat-home></maat-home>. In the DOM tree this component is placed after the router-outlet.

What can I do so the component <maat-home></maat-home> will take the remaining space?

Thanks!

like image 573
johan pujol Avatar asked May 12 '17 09:05

johan pujol


People also ask

Can we pass data in router outlet in Angular?

Angular 7.2. 0 introduced a new way to pass data using State Object while navigating between routed components. The benefit of using a state object is that you can share data between routed components with routeParams without displaying it on the URL segment, unlike queryParams in Angular.

Can there be more than one router outlet element in Angular application?

You can add multiple outlets in your Angular application which enables you to implement advanced routing scenarios. Any component that gets matched by the Router will render it as a sibling of the Router outlet.

What is outlet in Angular routing?

Router-Outlet is an Angular directive from the router library that is used to insert the component matched by routes to be displayed on the screen.


2 Answers

I found a way. The router-outlet is hidden and the component added on DOM have the attribute fxFlexFill for filling all available space.

<div fxLayout="column" fxFlexFill>
  <maat-top-bar class="top-bar"></maat-top-bar>
  <div fxFlex>
   <router-outlet class="hidden-router"></router-outlet>
  </div>
</div>

The class hidden-router

.hidden-router {
  flex: 1 1 auto;
  display: flex;
  overflow: hidden;
}

And the component

<div fxFlexFill="">
  I filling all remaining space
</div>
like image 89
johan pujol Avatar answered Sep 22 '22 00:09

johan pujol


Adding fxFlex to the <router-outlet> is probably not what you want. The component added by the router is added as a sibling, not as a child of <router-outlet>

like image 41
Günter Zöchbauer Avatar answered Sep 21 '22 00:09

Günter Zöchbauer