2

Need help! I'm using Angular 4. Where am using a sidebar as a separate component and showing the respective data on the right side of the sidebar. (i.e, if the user click link A1 on the sidebar, it should show A1's content on top to the right side of the sidebar). But Its not working I also tried using simple HTML href attribute to move to the particular div. It worked fine , But where I get the problem was When the user Clicks B's Link the page again starts loading the page again since B is another component. Is there any solution for this in angular?

And also If i scrolled to the middle of A's container and after clicking the link B it is not showing the container top it simply showing from the middle where i left the Container A. Any Solution ?enter image description here

VinoPravin
  • 947
  • 3
  • 17
  • 32
  • Please add some part of your code relevant to the issue in hand – NitinSingh Jun 02 '18 at 12:18
  • 1
    Your question cant be answered unless you provide your working demo code on https://stackblitz.com. With no code, we cant debug . and we cant write entire code ;) . Let us know once you have the demo ready. – Shashank Vivek Jun 02 '18 at 12:23

1 Answers1

0

The easy solution for your last problem:

import {Component} from '@angular/core';
import {NavigationEnd, Router} from '@angular/router';

@Component({
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
})
export class AppComponent {

  constructor(
    private readonly router: Router
  ) {
    this.router.events.subscribe((e) => {
      if (e instanceof NavigationEnd) {
        window.scrollTo(0, 0)
      }
    });
  }
}
Ivan Bisultanov
  • 438
  • 3
  • 8