Skip to content

Using Angular Http to load local files? #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
NathanWalker opened this issue May 20, 2016 · 0 comments
Closed

Using Angular Http to load local files? #249

NathanWalker opened this issue May 20, 2016 · 0 comments

Comments

@NathanWalker
Copy link
Contributor

NathanWalker commented May 20, 2016

Right now, doing this (assuming similar semantics that Image component uses for local src binding):

this.http.get(`~/assets/data.json`)
      .map((response: Response) => response.json())
      .subscribe((results: string[]) => {
        // never gets here
      });

Does not work.
Then only way I know to load a local file would be to use something like following:

let app = knownFolders.currentApp();
let localFile = app.getFile(`assets/data.json`);
localFile.readText().then((data) => {
  try {
    resolve(JSON.parse(data));
  } catch (err) {
    reject(err);         
  }
}, (err) => {
  reject(err);
}); 

That of course is not very intuitive to Angular devs.
Is there another way to do this using just Angular's Http?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant