Created
November 8, 2018 19:01
-
-
Save TaylorAckley/ddab5ddfd6f9af4ccc731469eda0be6c to your computer and use it in GitHub Desktop.
HATEOS Pipe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// link.model.ts | |
export class Link { | |
rel: string; | |
href?: string; | |
data?: any; | |
params?: any; | |
param?: any; | |
css?: string; | |
icon: string; | |
method?: HttpMethod; | |
} | |
export enum HttpMethod { | |
get, | |
post, | |
put, | |
patch, | |
delete | |
} | |
// Link Pipe | |
// ng create pipe link | |
import { Pipe, PipeTransform } from '@angular/core'; | |
import { Link } from '../models/api-response.model'; | |
@Pipe({ | |
name: 'link', | |
pure: false | |
}) | |
export class LinkPipe implements PipeTransform { | |
transform(links: Array<Link>, rel: string): Link { | |
return links.filter(link => link.rel === rel)[0]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment