Hi guys i am just starting to learn(upgrade to be specific) Angular 2, i just have some few questions. how do i iterate each object in the observable of array object?
this is what i retrieve if i go get data from "api/v1/example" already postman on this and yes its working. .
// my arrayObject
[
{
"userID": 12,
"username": "admin1",
"password": "admin2"
},
{
"userID": 13,
"username": "admin21",
"password": "admin32"
},
{
"userID": 14,
"username": "admin221",
"password": "admin72"
},
{
"userID": 15,
"username": "admin451",
"password": "admin652"
},
{
"userID": 16,
"username": "admin561",
"password": "admin1222"
},
{
"userID": 17,
"username": "admin154",
"password": "admin572"
},
{
"userID": 127,
"username": "admin1254",
"password": "admin5721"
}
]
So as what i said before i'm just learning angular 2, so i tried to use this dummy data to test observable, but somehow in my codes i can't really iterate each data in the object, this is what i tried so far
myData: Any[];
constructor(private _http: HttpClient) { }
ngOnInit() {
this._http.get<Any[]>("api/v1/example")
.map(data => data["username"])
.subscribe(data => console.log(data));
}
but i don't get any data, i even tried the filter
filter(data => data["id"] > 0)
but still fails, but if i just subscribe immediately like this i can retrieve the data
ngOnInit() {
this._http.get<Any[]>("api/v1/example")
.subscribe(data => console.log(data));
}
i use the stream in java as reference for this but i think they don't work the same, thank you in advance guys
this._http.get<Any[]>("api/v1/example")do you see 200 OK with the data as a response ?this._http.get<Any[]>("api/v1/example").pipe( map(d => { return d["username"]; }) ).subscribe(data => console.log(data));