Angular Resolver




    Angular snippets for TypeScript

    The code in this example imports the Injectable module from the Angular Core library. Next, the code imports the Resolve and ActivatedRouteSnapshot modules from the Angular Router library. Finally, the YourResolver class is exported and it implements the Resolve interface.

    In the resolve method, the code defines a resolve function that takes an ActivatedRouteSnapshot as an input. The resolve function returns an Observable object that will either emit an object representing the result of the route resolution or a Promise object that will be resolved when the route is resolved. The return type of the resolve function is an ObjectToResolve type.

    When the resolve function is called, the route parameter will be a ActivatedRouteSnapshot object. The route snapshot object will contain information about the route that was resolved. The information that is contained in the route snapshot object will vary depending on the router implementation that is used.

    In this example, the code uses the type hinting feature to declare the return type of the resolve function as ObjectToResolve. This will allow the resolve function to be used with any type of object that can be converted to an ObjectToResolve type.

    Library: angular

    Shortcut: a_resolver

    import { Injectable } from '@angular/core';
    import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
    import { Observable } from 'rxjs';
    @Injectable({ providedIn: 'root' })
    export class YourResolver implements Resolve<ObjectToResolve> {
      resolve(route: ActivatedRouteSnapshot): Observable<ObjectToResolve> | Promise<ObjectToResolve> | ObjectToResolve {
        return ${0};
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    • Security
    • Privacy Policy
    • Code Privacy
    • Terms of Service
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.