Skip to content

Using Angular Http to load local files? #249

Closed
@NathanWalker

Description

@NathanWalker

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions