RC3 removes the JSON load() method from CLI-generated Providers


#1

Are there plans to return the JSON-loading boilerplate load() method to Providers created with
ionic generate provider MyProvider
?

As of RC3, it looks like the CLI command no longer creates a JSON loader in its generated provider. Previously, it very helpfully looked like this:
import { Injectable } from ‘@angular/core’;
import { Http } from ‘@angular/http’;
import ‘rxjs/add/operator/map’;

@Injectable()
export class TestProvider {
  data: any;
 
  constructor(private http: Http) {
    this.data = null;
  }
 
  load() {
    if (this.data) {
      return Promise.resolve(this.data);
    }
 
    return new Promise(resolve => {
      this.http.get('path/to/data.json')
        .map(res => res.json())
        .subscribe(data => {
          this.data = data;
          resolve(this.data);
        });
    });
  }
}

Http get Request always must fired twice to work? Help pls
#2

I really really hope not. That code is dreadful. It makes a ghost promise, uses the explicit promise construction antipattern, doesn’t propagate errors correctly, and shouldn’t even be using promises in the first place. Http gives you a perfectly good Observable, simply use that.

And it also perpetuates overuse of any.


Unable to access the response in html file