ng-service2resolve
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

NgService2Resolve

npm version Downloads license

Simple way convert Service to Resolve.

Install

npm install ng-service2resolve

Getting Started

// Import method and function
import {  Service2ResolveModule, service2Resolve } from './service2resolve';

// deceive AOT compiler, fix `Function calls are not supported in decorators` problem
export let timeResolve = null, valueResolve = null;

// use service2Resolve function create Resolve class
timeResolve = service2Resolve([MyTestService], (services, route, state) => {
  return services[0].getTime();
});

const routes: Routes = [
  {
    path: '',
    pathMatch: 'full',
    component: MyTestComponent,
    resolve: {
      time: timeResolve //Add Routing Resolve,
      time2: service2Resolve(//this way not support AOT. If use this way, you can use findResolves function get all Resolve of routes
        [MyTestService],
        (services, route, state) => {
          return services[0].getTime();
        }
      )
    }
  }
];


@NgModule({
  imports: [
    Service2ResolveModule, // very important!
    RouterModule.forRoot(routes)
  ],
  providers: [findResolves(routes), timeResolve], // findResolves function NOT SUPPORT AOT
  exports: [RouterModule]
})
export class AppRoutingModule {}

Readme

Keywords

none

Package Sidebar

Install

npm i ng-service2resolve

Weekly Downloads

1

Version

1.0.3

License

MIT

Last publish

Collaborators

  • xupeiyao