#1. API
URL:  http://127.0.0.1/api/jobs/status
Return json: 
{"error":0,"data":[{"job_id":"s2323143455","status":"Enable","creator":
"user1","last-modified":"2016-04-20"},{"job_id":"sdfsdf132434","status":
"Enable","creator":"user2","last-modified":"2016-04-20"}]}

#2. job.service.ts
import {Injectable} from 'angular2/core';
import {Http} from 'angular2/http';
import {Observable} from 'rxjs/Observable';

@Injectable()
export class JobsService {
  constructor(public http: Http) {}

  private _jobsUrl = ' http://127.0.0.1/api/jobs/status'; 

  getJobStatus () {
    return this.http.get(this._jobsUrl)
                    .map(res => res.json());
  }

}
#3. job.component.ts
import {Component} from 'angular2/core';
import {JobsService} from './jobs.service'

@Component({
  selector: 'jobs',
  ...
    providers: [JobsService]
})
export class JobsComponent{
  jobs = "";

  constructor(
    private _jobService: JobsService
  ) {}

  getjobsStatus() {
    this._jobService.getJobStatus().subscribe(
      data => this.jobs = data,
      err => console.log(err)
    )
  }

  ngOnInit() {
   
    this.getjobsStatus();
    console.log('jobs data is ', this.jobs);
  }
}



why this.jobs always an empty object, I can't get the json data ?

anyone can help to fix, thanks a lot.

-- 
You received this message because you are subscribed to the Google Groups 
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.

Reply via email to