Fix for issue #5349. (#5560)

With this change, users providing custom configuration must provide an exported Configuration factory, rather than just an object. This is needed to be Angular AoT compatible.

Example use:

import * as api from '../api';

/** Configuration settings for the backend API */
export function backendConfigurationFactory(): api.Configuration {
    return new api.Configuration({basePath: '/api'});
}

@NgModule({
    imports: [api.ApiModule.forConfig(backendConfigurationFactory)],
...
This commit is contained in:
Adam Fanello 2017-05-13 20:52:10 -07:00 committed by wing328
parent d0d9650c13
commit fb04b5a26a
3 changed files with 6 additions and 6 deletions

View File

@ -16,10 +16,10 @@ import { {{classname}} } from './{{importPath}}';
providers: [ {{#apiInfo}}{{#apis}}{{classname}}{{#hasMore}}, {{/hasMore}}{{/apis}}{{/apiInfo}} ]
})
export class ApiModule {
public static forConfig(configuration: Configuration): ModuleWithProviders {
public static forConfig(configurationFactory: () => Configuration): ModuleWithProviders {
return {
ngModule: ApiModule,
providers: [ {provide: Configuration, useValue: configuration}]
providers: [ {provide: Configuration, useFactory: configurationFactory}]
}
}
}

View File

@ -14,10 +14,10 @@ import { UserService } from './api/user.service';
providers: [ PetService, StoreService, UserService ]
})
export class ApiModule {
public static forConfig(configuration: Configuration): ModuleWithProviders {
public static forConfig(configurationFactory: () => Configuration): ModuleWithProviders {
return {
ngModule: ApiModule,
providers: [ {provide: Configuration, useValue: configuration}]
providers: [ {provide: Configuration, useFactory: configurationFactory}]
}
}
}

View File

@ -14,10 +14,10 @@ import { UserService } from './api/user.service';
providers: [ PetService, StoreService, UserService ]
})
export class ApiModule {
public static forConfig(configuration: Configuration): ModuleWithProviders {
public static forConfig(configurationFactory: () => Configuration): ModuleWithProviders {
return {
ngModule: ApiModule,
providers: [ {provide: Configuration, useValue: configuration}]
providers: [ {provide: Configuration, useFactory: configurationFactory}]
}
}
}