
BREAKING CHANGE - Pipe factories have been removed. - PIpe names to pipe implementations are 1-to-1 instead of 1-to-* Before: class DateFormatter { transform(date, args){} } class DateFormatterFactory { supporst(obj) { return true; } create(cdRef) { return new DateFormatter(); } } new Pipes({date: [new DateFormatterFactory()]}) After class DateFormatter { transform(date, args){} } new Pipes({date: DateFormatter})
33 lines
674 B
TypeScript
33 lines
674 B
TypeScript
import {isBlank, isPresent, Json, CONST} from 'angular2/src/facade/lang';
|
|
import {Injectable} from 'angular2/di';
|
|
import {Pipe, BasePipe} from './pipe';
|
|
|
|
/**
|
|
* Implements json transforms to any object.
|
|
*
|
|
* # Example
|
|
*
|
|
* In this example we transform the user object to json.
|
|
*
|
|
* ```
|
|
* @Component({
|
|
* selector: "user-cmp"
|
|
* })
|
|
* @View({
|
|
* template: "User: {{ user | json }}"
|
|
* })
|
|
* class Username {
|
|
* user:Object
|
|
* constructor() {
|
|
* this.user = { name: "PatrickJS" };
|
|
* }
|
|
* }
|
|
*
|
|
* ```
|
|
*/
|
|
@CONST()
|
|
@Injectable()
|
|
export class JsonPipe extends BasePipe {
|
|
transform(value: any, args: List<any> = null): string { return Json.stringify(value); }
|
|
}
|