`scrollOffset` option isn't available in Angular 17's new `bootstrapApplication` function

425 views Asked by At

I am unable to add a scrollOffset option to my Angular 17 bootstrap config.

Before Angular 17, you'd have an app module that imports a routing module as such:

import { NgModule } from '@angular/core';
import { PreloadAllModules, RouterModule, Routes } from '@angular/router';

const routes: Routes = [
  {
    path: '',
    component: HomeComponent,
  },
];

@NgModule({
  imports: [
    RouterModule.forRoot(routes, {
      initialNavigation: 'enabledBlocking',
      scrollPositionRestoration: 'enabled',
      anchorScrolling: 'enabled',
      scrollOffset: [0, 100],
      preloadingStrategy: PreloadAllModules,
    }),
  ],
  exports: [RouterModule]
})
export class AppRoutingModule { }

In Angular 17, you now pass a config object to the bootstrapApplication function, and I am unable to find a way to add the scrollOffset config as before (see above):

// main.ts

import { bootstrapApplication } from '@angular/platform-browser';
import { appConfig } from './app/app.config';
import { AppComponent } from './app/app.component';

bootstrapApplication(AppComponent, appConfig)
  .catch((err) => console.error(err));
// app.config.ts
import { ApplicationConfig } from '@angular/core';
import { withInMemoryScrolling } from '@angular/router';
import { routes } from './app.routes';

export const appConfig: ApplicationConfig = {
  providers: [
    provideRouter(
      routes,
      withInMemoryScrolling({
        scrollPositionRestoration: 'enabled',
        anchorScrolling: 'enabled',
      }),
      // Where can I put my scrollOffset???
    ),
  ],
};
1

There are 1 answers

2
Matthieu Riegler On BEST ANSWER

It is intentional that scrollOffset as removed when building the standalone API because the option is a duplicate of what's already available in ViewportScroller. Instead, call you should call ViewportScroller.setOffset().