如何使用 ng2-resource-rest 和 typeScript 处理 Angular2 中的 400/500 状态等休息调用错误?
注册组件.ts
registerEmployees() {
let regEmployee = this.empService.employeeRegister(this.register);
regEmployee.$observable
.subscribe(
(data: any) = > {
regEmployee = data;
}
),
(error: any) = > {
// I also made a layer to parse errors
};
}
员工服务.ts
import{ Injectable } from '@angular/core';
import{ RequestMethod, Response } from '@angular/http';
import{ ResourceAction, ResourceMethod, ResourceParams } from 'ng2-resource-rest';
import{ RestClient } from './global/rest-client';
@Injectable()
@ResourceParams({
url: 'http://localhost:8080/api/v1'
})
export class EmployeeServiceService extends RestClient {
@ResourceAction({
method: RequestMethod.Post,
path : '/employee'
})
employeeRegister: ResourceMethod<any, any>;
}