0.1.2 • Published 7 years ago

ng2-serverless-spa-plugin v0.1.2

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

alt text

serverless npm version npm npm

The serverless-ng2-spa-plugin is a plugin for Angular2/Angular4 projects and is an additional support for the dynamic-URL-generation in the Serverless SPA Plugin.

Setup

Install via npm in your angular-project

npm install ng2-serverless-spa-plugin

Add the plugin to the providers in your module (app.module.ts).

import {RequestOptions, XHRBackend} from '@angular/http';
import {FrameworkProjectHttp} from 'ng2-framework-project';

export function httpFactory(backend: XHRBackend, defaultOptions: RequestOptions) {
  return new FrameworkProjectHttp(backend, defaultOptions)
}
//...
@NgModule({
  //...
  providers: [
      {
        provide: FrameworkProjectHttp,
        useFactory: httpFactory,
        deps: [XHRBackend, RequestOptions]
      }
    ]
})

Usage

Import FrameworkProjectHttp in the services of the project

import {FrameworkProjectHttp} from 'ng2-framework-project';

Use the methods from FrameworkProjectHttp instead of the methods from Http from @angular/http and the relative URL instead of the absolute URL.

constructor(private http: FrameworkProjectHttp) {}

private relativePath = '/examples'

getTodos() {
    return this.http.get(this.relativePath, {headers: this.headers})
}