在HATEOAS链接的支持下,我有一个安静的Web服务.我打电话的时候
“ http://localhost:8080/v1/bookings/1225380?lock=true”
链接我得到了以下资源URL.我想将这些Hypermedia与我的Angular2应用程序(最近升级到最终版本)集成.我发现Angular1在Angular HAL的支持下实现的资源很少(链接 – https://paulcwarren.wordpress.com/2015/04/03/role-based-spas-with-angularjs-and-spring-hateoas/,https://github.com/LuvDaSun/angular-hal/tree/master/src).但我无法找到Angular2的资源.
“ http://localhost:8080/v1/bookings/1225380?lock=true”
链接我得到了以下资源URL.我想将这些Hypermedia与我的Angular2应用程序(最近升级到最终版本)集成.我发现Angular1在Angular HAL的支持下实现的资源很少(链接 – https://paulcwarren.wordpress.com/2015/04/03/role-based-spas-with-angularjs-and-spring-hateoas/,https://github.com/LuvDaSun/angular-hal/tree/master/src).但我无法找到Angular2的资源.
"links": [ { "rel": "client","href": "http://localhost:8080/v1/clients/10000" },{ "rel": "passengers","href": "http://localhost:8080/v1/bookings/1225380/passengers" },{ "rel": "itinerary","href": "http://localhost:8080/v1/bookings/1225380/itinerary" },{ "rel": "self","href": "http://localhost:8080/v1/bookings/1225380?lock=true" },{ "rel": "clientBookingHistory","href": "http://localhost:8080/v1/bookings/1225380/clientBookingHistory/10000" } ]
解决方法
您可以为此创建一个Injectable,并使用此类而不是角度http类.在这里,您可以过滤链接,然后使用正确的链接调用http.
@Injectable() export class Hypermedia { constructor(private http: Http) { } get(links: any[],rel: String,body?: any,options?: RequestOptionsArgs): Observable<Response> { var link = null; var request = null; // Find the right link links.forEach(function (_link) { if (_link.rel === rel) { link = _link return; } }); return this.http.get(link.href); }
}
constructor(private hypermedia:Hypermedia)
this.hypermedia.get(myHypermediaLinksArray,myRel)
希望这可以帮助:)