Angular 2 - Injectable issue- unable to pass array/data

problem with injectable… I’m not sure if getdata() function is actually working.
far as the the line querying the database, it works but not sure if the variable “data” is receiving the data.

how do i determine if " return" actually contains the data pulled from the database?

import {Injectable} from '@angular/core';
import {Http, Response} from '@angular/http';
import {UserType} from '../usertype';

export class LoginService {
    public data:UserType[];

    constructor(private http:Http){  } 
       .subscribe(res => = res.json());

Hey @robin01,

This code won’t work, because as soon as you call getData() it will return the current value of (probably undefined, unless you’re initializing it to a default value) before the HTTP request has completed.

Have a look at the Angular 2 docs for the HTTP client. There are some examples of how to deal with getting data back from HTTP requests when dealing with observables.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.