Skip to content

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Repository files navigation

Angular4Tools

My angular4 useful tools

Environment variables

export const environment = {
  production: false,
  api: {
    prefix: 'api',
    version: 'v1',
    url: 'example.com',
    config: {
      ssl: true
    }
  }
};

ConfigService

An injectable config service for getting e.g API URL to HTTP requests. For variables from above the service returns URL like https://api.example.com/v1/

@Injectable()
export class ConfigService {
  public getApiUrl( path: string ): string {
    if ( path.substr(0, 1) == '/' )
      path = path.replace('/', '');

    return this.getApiEndPoint() + '/' + path;
  }
}

ExtHttp service

An injectable service which extends Http and adds API URL to each request.

// app.module.ts
export function eHttp(backend: XHRBackend, options: RequestOptions, configService: ConfigService) {
  return new ExtHttp(backend, options, configService);
}

@NgModule({
  ...
  providers: [
    ConfigService,
    {
      provide: ExtHttp,
      useFactory: eHttp,
      deps: [XHRBackend, RequestOptions, ConfigService]
    }
  ],
  ...
})
// our component class
constructor(private extHttp: ExtHttp) {
  let q = new URLSearchParams();
  q.set('q', 'query');

  this.extHttp.get('search', { search: search }).subscribe((response: Response) => {
    // logic
  });
}

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages