Guide for implementing overflow-y on a router-outlet in Angular

I am a newcomer to bootstrap and angular, so I'm unsure where I may have made a mistake...

Here is the current situation:

Initially, I utilize a router-outlet to showcase either a login-page or the "workspace".

<app-header ></app-header>
<router-outlet></router-outlet>

within 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 includes a component that requires overflow-y: auto

Unfortunately, the overflow-auto from Bootstrap does not seem to work!

This is how the application appears

When I try setting the height of div#needsOverflow to 600px, I notice that the overflow does not extend all the way to the end of my screen. How can I make it reach across the entire screen? I attempted using height = 100vh but this proved too large due to my header.

My goal is for the 2nd router-outlet to have overflow-y only when the content exceeds the screen size, In simpler terms, it's fine for my side-nav and header to remain fixed in place

I also experimented with mat-sidenav, however, I encountered numerous issues likely stemming from the header

Answer №1

I was able to resolve the entire issue by incorporating a directive!

Here is the updated code in app-component html:

<app-header viewportheight></app-header>
<div>
  <router-outlet></router-outlet>
</div>

The new viewportheight.directive implementation:

@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)
 }
}

In workspace.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>

The variable height is now subscribed to a BehavourSubject in my viewportheightService.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Using Angular 13 causes Bootstrap 5 dropdowns to not open as expected

Hello everyone, I'm currently working on an angular project and incorporating bootstrap 5. I'm encountering an issue with an expanded dropdown multiselect feature that I'm trying to implement. For reference, I've been following this ex ...

Using the ternary operator in various CSS rules

Inside a .hover() function, I've written the code below: $(this).css('background-position', circle.includesXY(e.pageX, e.pageY) ? 'bottom' : ''); I'm wondering how to include additional property:value pairs within ...

Challenges in handling asynchronous data within static JSON objects in Angular2

I have a service set up with some static objects that are being utilized in my UI. fetchRulesVariables() fetchRuleVariables() { let variables = [ { name: 'Credit Funding Type', id: 1, multiple: ...

The click event is activated following the :active selector being triggered

My Angular application features a button with a slight animation - it moves down by a few pixels when clicked on: &:active { margin: 15px 0 0 0; } The button also has a (click)="myFunction()" event listener attached to it. A common issue arises w ...

In-depth CSS Reset for specific tags

Creating a Firefox extension that inserts HTML elements into web pages poses the challenge of ensuring consistent styling across various websites. The CSS rules must be robust enough to override any potential modifications introduced by developers. This ta ...

Tips on updating the arrow icon after clicking on a dropdown menu

HTML: <div class="customSelectContainer"> <ul> <li class="initial">Choose</li> <li data-value="value 1">Option 1</li> <li data-value="value 2">Option 2& ...

Guide on altering the bar colors based on their values with the help of the ApexCharts library and the Angular framework

I'm facing an issue with a component that displays a graph with 2 series: Indicators and Bonus. The rule I set is that when the value ranges from 0 to 99, the bar turns red. If it's greater than 99, the bar should be green. This works fine for t ...

What is the reason for the ineffectiveness of percentage padding/margin on flex items in Firefox and Edge browsers?

I am trying to create a square div within a flexbox. Here is the code I have used: .outer { display: flex; width: 100%; background: blue; } .inner { width: 50%; background: yellow; padding-bottom: 50%; } <div class="outer"> <div c ...

Text enclosed within a two-column div displayed in a single line

When working with a two column layout using divs instead of a table, I encountered an issue with displaying the content properly when the text in the first column is too long. For instance, I want 'Spoken' to be inline with 'English', b ...

Troubleshooting Cors Problem between Angular 2 Form Data and Express

I'm attempting to send some files to an Express server that utilizes the cors() module in the following way app.use(cors()); This is the Angular 2 code used for file uploading let formData:FormData = new FormData(); for(let i = 0; i < files. ...

I'm curious as to why I am receiving an empty array as a response when I send a post request to the API

I am experiencing an issue while sending data to an API using a post method. I have structured the data in an object as per the server's requirements, but upon posting the object to the API, I receive a response with a status of 200 and an empty array ...

What steps should I take to design a polished PDF document?

I have been tasked with automating the invoicing system at our company. Currently, all data is stored in a local MySQL database and someone manually updates an Excel spreadsheet, which is then merged into a MS Word template for generating invoices. The obj ...

Unique custom navigation bar (priority menu) crafted with Bootstrap 5 without any reliance on JQuery technology

Looking to craft a unique Bootstrap 5 custom responsive navbar (priority nav) with a "show More..." feature using Vanilla JS because I have numerous menu items and can't utilize jQuery. Bootstrap navbars don't adapt well to varying screen widths ...

What is the best way to adjust the size of the initial text field in a Bootstrap input group

I'm attempting to incorporate a country code and phone number using Bootstrap v5 input group. Unfortunately, the code I'm using doesn't seem to be functioning correctly. I would like the format to be adjusted by changing the width. Is that ...

The exception org.openqa.selenium.NoSuchElementException occurs when the specified element cannot be found on the web page

I can't seem to find the correct xpath or locate this element using Selenium. I keep getting this error: FAILED: homeLoan("John Smith", "[email protected]", "Australia", "1563", "62365896410", "Home Loan", "Buying", "100000", "50000") org.openqa ...

Encountering a compilation error while compiling using Angular Ivy

Encountering a compile time error in my Angular 8 project when enabling angular Ivy. Upgrading to version 8.1.0 did not solve the issue, and I continue to receive the following error: D:\Users\Backup>ng build shared Building Angular Package B ...

Visual Studio is not recognizing at-rules

Currently implementing code found at this URL: This code includes: @-webkit-keyframes moveclouds { 0% {margin-left: 1000px;} 100% {margin-left: -1000px;} } @-moz-keyframes moveclouds { 0% {margin-left: 1000px;} 100% {margin-left: -1000px;} } @-o-keyframe ...

When the value equals 25

I am seeking to implement a text field where users can input a number, and based on whether it's correct or not, display "image a" for the correct answer and "image b" for an incorrect one below the text field. I want users to have multiple attempts u ...

Achieve uniform display across browsers: Implement Chrome's overflow ellipsis feature on Firefox

I am seeking a CSS solution to achieve the same "overflow: hidden" and "text-overflow: ellipsis" behavior in Firefox as I get in Chrome. In Chrome, when the width of the tag is reduced, the text gets hidden and replaced with an ellipsis. However, in Firefo ...

The lower div is overlapping the upper div in a smaller viewport

I have integrated some dashboard widgets in iframes and I want to ensure they are responsive. My goal is for each widget to occupy full width when the screen size is reduced, but appear side by side when the browser window is large (md+): iframe { b ...