Angular 2工厂提供商

时间:2017-02-27 00:14:38

标签: angular typescript auth0

如果我创建这样的文件(auth.module.ts):

import { NgModule } from '@angular/core';
import { Http, RequestOptions } from '@angular/http';
import { AuthHttp, AuthConfig } from 'angular2-jwt';

export function authHttpServiceFactory(http: Http, options: RequestOptions) {
  return new AuthHttp(new AuthConfig(), http, options);
}

@NgModule({
  providers: [
    {
      provide: AuthHttp,
      useFactory: authHttpServiceFactory,
      deps: [Http, RequestOptions]
    }
  ]
})
export class AuthModule {}

并在app.module.ts

中声明/导入它
import {AuthModule} from "./services/auth.module";

@NgModule({
  declarations: [
    AppComponent,
    ...
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    ...
    AuthModule
  ],
  providers: [
    ...
  ],
  bootstrap: [AppComponent]
})

我如何从我的服务中获得AuthHttp提供商?

谢谢!

(如果需要更多上下文here

0 个答案:

没有答案