Files
andrewmcgivery f61a57b9ee Typescript generators
* @Inject to parameters()

Changed injection of Http to use parameters() instead of @Inject

* import map operator

Added import of map operator from rxjs

* Typescript Generator Support

Support for typescript generators

* Tabs -> spaces

* Changes From Tim's Feedback
2016-04-04 09:30:55 -05:00

45 lines
1.1 KiB
JavaScript

import {Injectable} from 'angular2/core';
import {Http} from 'angular2/http';
import 'rxjs/add/operator/map';
/*
Generated class for the <%= jsClassName %> provider.
See https://angular.io/docs/ts/latest/guide/dependency-injection.html
for more info on providers and Angular 2 DI.
*/
@Injectable()
export class <%= jsClassName %> {
static get parameters(){
return [[Http]]
}
constructor(http) {
this.http = http;
this.data = null;
}
load() {
if (this.data) {
// already loaded data
return Promise.resolve(this.data);
}
// don't have the data yet
return new Promise(resolve => {
// We're using Angular Http provider to request the data,
// then on the response it'll map the JSON data to a parsed JS object.
// Next we process the data and resolve the promise with the new data.
this.http.get('path/to/data.json')
.map(res => res.json())
.subscribe(data => {
// we've got back the raw data, now generate the core schedule data
// and save the data for later reference
this.data = data;
resolve(this.data);
});
});
}
}