W3cubDocs

/Angular

mapToResolve

function

Maps an injectable class with a resolve function to an equivalent ResolveFn for use in a Route definition.

See more...

mapToResolve<T>(provider: Type<{ resolve: ResolveFn<T>; }>): ResolveFn<T>

Parameters
provider Type<{ resolve: ResolveFn<T>; }>
Returns

ResolveFn<T>

See also

Description

Usage

@Injectable({providedIn: 'root'})
export class ResolveUser {
  resolve() {
    return {name: 'Bob'};
  }
}

const userRoute: Route = {
  path: 'user',
  resolve: {
    user: mapToResolve(ResolveUser),
  },
};

© 2010–2023 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/api/router/mapToResolve