如何消费服务数据* ngFor

问题描述:

在这里,我访问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(); }) –

您需要从服务中返回数据并将其绑定到组件内部,

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

谢谢很多Sajee Bhai –