Skip to content

Instantly share code, notes, and snippets.

@jrwebdev
Created November 14, 2016 07:00
Show Gist options
  • Save jrwebdev/46e0c430f0e7b47610e8aacdb466efa8 to your computer and use it in GitHub Desktop.
Save jrwebdev/46e0c430f0e7b47610e8aacdb466efa8 to your computer and use it in GitHub Desktop.
Angular 1 Filters vs Angular 2 Pipes
// 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