-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
AzSiAz
committed
Jul 19, 2016
1 parent
3d7e47c
commit e4f84a8
Showing
4 changed files
with
133 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Injectable } from '@angular/core'; | ||
import { Http } from '@angular/http'; | ||
import 'rxjs/add/operator/map'; | ||
|
||
/* | ||
Generated class for the LocalStorage provider. | ||
See https://angular.io/docs/ts/latest/guide/dependency-injection.html | ||
for more info on providers and Angular 2 DI. | ||
*/ | ||
@Injectable() | ||
export class LocalStorage { | ||
data: any; | ||
|
||
constructor(private 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); | ||
}); | ||
}); | ||
} | ||
} | ||
|