How to navigate to certain section of the page identified with an id attribute?
Example:
I need to navigate to \"structure\" paragraph on my page
Angular 2: I would prefer to go with scrollIntoView() method scrollIntoView. It would provide smooth scrolling transition effect in the browser.
HTML Code
Info
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
Structure
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
-
and in the Component.
@Component({
selector: 'my-app',
template: `template.html `
})
export class AppComponent {
@ViewChild('structure') public structure:ElementRef;
@ViewChild('info') public info:ElementRef;
public moveToStructure():void {
this.structure.nativeElement.scrollIntoView({ behavior: 'smooth', block: 'end', inline: 'start' });
}
public infoStruc():void {
setImmediate(() => {
this.info.nativeElement.scrollIntoView({ behavior: 'smooth', block: 'end', inline: 'start' });
});
}
}