I have already coded my app.component.ts file to scroll to the top of my app after every page state change using renderer.setElementProperty.
I also have a example.com/product/xx page where the 'xx' represents a different param. I have coded a route.param.subscribe to listen for param changes and fetch the content of the page based on the new parameter.
My issue is primarily on mobile phones (browser view) or pages with longer content.
My code listens for param changes, updates the content but does not scroll to the top of the page, although my app.component.ts file accomplishes this with my standard route changes.
I have tried window.scrollTo(0, 0) and a couple of other JavaScript based window actions to no avail.
Has anyone successfully coded a scroll back to top functionality inside of a routes param subscription?
coded as seen below
this.route.params
.subscribe(item => {
this.item = item; // successfully retrieves param content
window.scrollTo(0, 0); // does not scroll to top
this.renderer.setElementProperty(document.body, "scrollTop", 0);
// also does not work
});
});
Any ideas to property inject a "scroll to top" functionality after successfully listening to params from route in an Angular 4 (4.4.x) app?