Jump to content
Sign in to follow this  

Guardar data de JSON em variavel Angular 2

Recommended Posts


Boa noite,

Estou a tentar buscar um ficheiro json e guardar uma variavel dentro do TypeScript.

Json file

[{ "name":"John", "age":31, "city":"New York" },
{ "name":"Joana", "age":32, "city":"California" }
export class AppComponent {
      this.http.get('./file.json').map((res: Response) => res.json()).subscribe(res => this.result = res);

No alert gostava de  retornar John, só que infelizmente só me dá "undefined name"





Edited by CloudPT

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.