This is part of ongoing work to make core platform-independent. BREAKING CHANGE All private exports from 'angular2/src/core/facade/{lang,collection,exception_handler}' should be replaced with 'angular2/src/facade/{lang,collection,exception_handler}'.
33 lines
798 B
TypeScript
33 lines
798 B
TypeScript
import {isBlank, isPresent, Json, CONST} from 'angular2/src/facade/lang';
|
|
import {Injectable} from 'angular2/src/core/di';
|
|
import {PipeTransform, WrappedValue} from 'angular2/src/core/change_detection';
|
|
import {Pipe} from 'angular2/src/core/metadata';
|
|
|
|
/**
|
|
* Implements json transforms to any object.
|
|
*
|
|
* ### Example
|
|
*
|
|
* In this example we transform the user object to json.
|
|
*
|
|
* ```
|
|
* @Component({
|
|
* selector: "user-cmp",
|
|
* template: "User: {{ user | json }}"
|
|
* })
|
|
* class Username {
|
|
* user:Object
|
|
* constructor() {
|
|
* this.user = { name: "PatrickJS" };
|
|
* }
|
|
* }
|
|
*
|
|
* ```
|
|
*/
|
|
@CONST()
|
|
@Pipe({name: 'json', pure: false})
|
|
@Injectable()
|
|
export class JsonPipe implements PipeTransform {
|
|
transform(value: any, args: any[] = null): string { return Json.stringify(value); }
|
|
}
|