2017-04-16 38 views
0

在這裏,我訪問HTTP服務創建一個簡單的服務,請helpme我如何能在* ngFor如何消費服務數據* ngFor

import { Component } from '@angular/core'; 
    import {Http } from '@angular/http'; 
import { Injectable } from '@angular/core'; 
    @Injectable() 
    export class EmployeeService { 
     constructor(private http: Http) { } 
    GetStudentData() { 

     this.http.get('api/Employee').subscribe(response => { 

      this.student = response.json(); 
       }) 
    } 
    } 

Student.component.ts綁定此服務的信息

GetStudentData() { 
     var studentser = this.EmpServ.GetStudentData(); 
        //Here How can i Bind 

    } 

她如何將數據保存在一個變量中並用於

+0

https://angular.io/docs/ts/latest/guide/dependency-injection.html –

+0

你是什麼意思通過創建一個簡單的構造函數來訪問http服務? – Sajeetharan

+0

yes在這裏訪問這個http就像this.http.get('api/Employee')。subscribe(response => { this.student = response.json(); }) –

回答

0

您需要從服務中返回數據並將其綁定到組件內部,

GetStudentData() { 
     this.http.get('api/Employee').subscribe(response => { 
     this.student = response.json(); 
     }) 
    return this.student; 
} 
+0

謝謝很多Sajee Bhai –