This is my server data:
[
{
"name" : "testname"
},
{
"name" : "testnametwo"
}
]
I am trying to get this data using Angular2 http.get. I am trying with below code:
private _url : string = "appone/api/user.json"
user = []
constructor(private http : Http) { }
getUsers() {
let res = this.http.get(this._url).map((response : Response) => {
return response.json()
})
res.subscribe((data) => {
this.user = data
})
alert(this.user.name)
}
But I didn't get any result. I don't know where I am wrong.
Any help is greatly appreciated.