import { Injectable } from '@angular/core'; import { Http, Headers, Response, RequestOptions } from "@angular/http"; import { Observable as RxObservable } from "rxjs/Observable"; import "rxjs/add/operator/map"; {{#each collections}} @Injectable() //--------------------------------- // data class //--------------------------------- class {{tsClassPropertyName this.name}}Model { {{#each model}} public {{@key}}: {{tsPropertyType this}}{{#if @last}}{{else}}; {{/if}} {{/each}} constructor(private http: Http) {} private serverUrl = {{path}}; {{#if methods}}{{#each methods}} {{#if get}} get(): any { let options = this.createRequestOptions(); return this.http.get(this.serverUrl, { data }, options) .map(res => res.json()); } {{/if}} {{#if put}} get(): any { let options = this.createRequestOptions(); return this.http.put(this.serverUrl, { data }, options) .map(res => res.json()); } {{/if}} {{#if post}} {{/if}} {{#if delete}} {{/if}} {{/each}}{{/if}} private createRequestOptions() { let headers = new Headers(); headers.append("AuthKey", "my-key"); headers.append("AuthToken", "my-token"); headers.append("Content-Type", "application/json"); let options = new RequestOptions({ headers: headers }); return options; } } {{/each}}