diff --git a/docs/pipes.md b/docs/pipes.md index e69de29..37ebd08 100644 --- a/docs/pipes.md +++ b/docs/pipes.md @@ -0,0 +1,56 @@ +# Pipes + +Pipes transform output in the template. + +overview + +The Data remains the same as the output change. + +The right place to place a pipe, is in the template. + +Example of piping +```html +
  • + + {{ server.status }} + + {{ server.name | shorten:15 }} | + {{ server.instanceType | uppercase }} | + {{ server.started | date:'fullDate' | uppercase }} +
  • +``` + +Chaining the pipes together the order is important. + +Angular pipe [documentation](https://angular.io/api?query=pipe) + +## Create custom pipe + +```ts +import { Pipe, PipeTransform } from '@angular/core'; + +@Pipe({ + name: 'filter', + pure: false +}) +export class FilterPipe implements PipeTransform { + + transform(value: any, filterString: string, propName: string): any { + if (value.length === 0 || filterString === '') { + return value; + } + const resultArray = []; + for (const item of value) { + if (item[propName] === filterString) { + resultArray.push(item); + } + } + return resultArray; + } + +} +``` \ No newline at end of file diff --git a/img/pipes.png b/img/pipes.png new file mode 100644 index 0000000..780c585 Binary files /dev/null and b/img/pipes.png differ