mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-23 14:01:20 +08:00
chore(generators): update provider generator
This commit is contained in:
@ -16,29 +16,7 @@ export class <%= jsClassName %> {
|
|||||||
|
|
||||||
constructor(http) {
|
constructor(http) {
|
||||||
this.http = 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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,32 +10,8 @@ import 'rxjs/add/operator/map';
|
|||||||
*/
|
*/
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class <%= jsClassName %> {
|
export class <%= jsClassName %> {
|
||||||
data: any;
|
|
||||||
|
|
||||||
constructor(private http: Http) {
|
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);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user