Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { ENV_PROVIDERS } from './environment';
- import { APP_RESOLVER_PROVIDERS } from './app.resolver';
- // Application wide providers
- const APP_PROVIDERS = [
- ...APP_RESOLVER_PROVIDERS,
- AppState,
- AppConfig
- ];
- @NgModule({
- bootstrap: [ App ],
- declarations: [ ... ],
- imports: [ ... ],
- providers: [
- ENV_PROVIDERS,
- APP_PROVIDERS
- ]
- })
- export class AppModule {
- import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
- import { Injectable } from '@angular/core';
- import { Observable } from 'rxjs/Observable';
- import 'rxjs/add/observable/of';
- @Injectable()
- export class DataResolver implements Resolve<any> {
- constructor() {
- }
- resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
- return Observable.of({ res: 'I am data'});
- }
- }
- // an array of services to resolve routes with data
- export const APP_RESOLVER_PROVIDERS = [
- DataResolver
- ];
- // Angular 2
- // Environment Providers
- let PROVIDERS: any[] = [
- // common env directives
- ];
- if ('production' === ENV) {
- PROVIDERS = [
- ...PROVIDERS,
- // custom providers in production
- ];
- } else {
- // Development
- PROVIDERS = [
- ...PROVIDERS,
- // custom providers in development
- ];
- }
- export const ENV_PROVIDERS = [
- ...PROVIDERS
- ];
- @NgModule({
- imports: [ CommonModule, HttpModule ],
- declarations: [],
- exports: [],
- providers: [ UsersService ]
- })
- export class ApiModule {
- public static forConfig(configuration: Configuration): ModuleWithProviders {
- return {
- ngModule: ApiModule,
- providers: [ {provide: Configuration, useValue: configuration}]
- }
- }
- }
- export interface ConfigurationParameters {
- apiKey?: string;
- username?: string;
- password?: string;
- accessToken?: string;
- basePath?: string;
- }
- export class Configuration {
- apiKey: string;
- username: string;
- password: string;
- accessToken: string;
- basePath: string;
- constructor(configurationParameters: ConfigurationParameters = {}) {
- this.apiKey = configurationParameters.apiKey;
- this.username = configurationParameters.username;
- this.password = configurationParameters.password;
- this.accessToken = configurationParameters.accessToken;
- this.basePath = configurationParameters.basePath;
- }
- }
- @Injectable()
- export class UsersService {
- protected basePath = 'http://localhost/commty/cmng';
- public defaultHeaders: Headers = new Headers();
- public configuration: Configuration = new Configuration();
- constructor(protected http: Http, @Optional()@Inject(BASE_PATH) basePath: string, @Optional() configuration: Configuration) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement