【发布时间】:2017-08-25 21:39:21
【问题描述】:
我有节点 api,它使用这个 api 将数据返回给浏览器:
app.get('/api/patients',function(req,res){
Patient.getPatients(function(err,patients){
if(err){
throw err;
}
console.log(patients.length);
res.json(patients);
});
});
我正在尝试从服务类调用此 api。
import { Injectable } from '@angular/core';
import { Patient } from '../patient.interface';
@Injectable()
export class PatientDataService {
patients : Patient[] =[];
constructor() { }
getAllPatients(): Patient[]
{
// What to do here ??
}
}
如何将数据从节点 api 返回到服务?
【问题讨论】:
-
我认为上面的代码来自angular2
-
@PankajParkar 这是 Angular 2 应用程序,而不是 AngularJS (1) 应用程序。
-
我的错.. 没有查看 Angular 2 标签.. 虽然它与
http.get相同