我在nodeJs中写了我的Api。我从Api获得了数据但是在[[object Object],[object Object]]这个格式中。当我将这个数组设置为我的数组变量时,它给出了空数组。请帮我如何将这个数组分配到我定义的数组变量?
我的员工服务
import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import 'rxjs/Rx';
@Injectable()
export class EmployeeService {
private baseUrl = 'http://localhost:5000/Role';
constructor(private _http: Http) { }
getRoleData() {
const url = 'http://localhost:5000/Role';
return this._http.get(url)
.map(x => x.json());
}
EmployeeComponent.ts
import { Component, OnInit, ViewChild } from '@angular/core';
import { Response } from '@angular/http';
import { Employee, EmployeeService } from './employee-service';
import { Role } from '../../Modules/Role.module';
@Component({
selector: 'app-employee-master',
templateUrl: './employee-master.component.html',
styleUrls: ['./employee-master.component.scss'],
providers: [EmployeeService]
})
export class EmployeeMasterComponent implements OnInit {
roles: Role[] = [];
constructor(private employeeService: EmployeeService) {}
ngOnInit() {
this.employeeService.getRoleData().subscribe(x => this.roles = x);
console.log("Role" + this.roles);
}
}
角色模块
export class Role {
public OID: number;
public RollNo: string;
public RollName: string;
public GCRecord: string;
public OptimisticLockField: string;
constructor(OID: number, RollNo: string, RollName: string, GCRecord: string, OptimisticLockField:string) {
this.OID = OID;
this.RollNo = RollNo;
this.RollName = RollName;
this.GCRecord = GCRecord;
this.OptimisticLockField = OptimisticLockField;
}
}
我的api回复
[
{
"GCRecord": null,"OID": 1,"RollNo": "1","RollName":
"HR","OptimisticLockField": null
},
{
"GCRecord": null,
"OID": 2,
"RollNo": "2",
"RollName": "Admin",
"OptimisticLockField": null
}]