Created
November 14, 2016 07:00
-
-
Save jrwebdev/46e0c430f0e7b47610e8aacdb466efa8 to your computer and use it in GitHub Desktop.
Angular 1 Filters vs Angular 2 Pipes
This file contains hidden or 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
// Angular 1 | |
const module = angular.module('myModule', []); | |
module.filter('kebabCase', () => (input) => input.toLowerCase().replace(' ', '-')); | |
/***************************************************************/ | |
// Angular 2 | |
import {Pipe, PipeTransform} from '@angular/core'; | |
@Pipe({name: 'kebabCase'}) | |
class KebabCasePipe implements PipeTransform { | |
transform(input: string): string { | |
return input.toLowerCase().replace(' ', '-') | |
} | |
} | |
// Usage (Angular 1 + Angular 2) | |
// {{'Hello World' | kebabCase}} | |
// 'hello-world' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment