2015-11-06 17:34:07 -08:00
|
|
|
import {isBlank, isPresent, Json, CONST} from 'angular2/src/facade/lang';
|
2015-09-03 22:01:36 -07:00
|
|
|
import {Injectable} from 'angular2/src/core/di';
|
|
|
|
import {PipeTransform, WrappedValue} from 'angular2/src/core/change_detection';
|
|
|
|
import {Pipe} from 'angular2/src/core/metadata';
|
2015-05-18 09:24:52 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements json transforms to any object.
|
|
|
|
*
|
2015-10-19 15:37:32 +01:00
|
|
|
* ### Example
|
2015-05-18 09:24:52 -07:00
|
|
|
*
|
|
|
|
* In this example we transform the user object to json.
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
* @Component({
|
2015-10-11 07:41:19 -07:00
|
|
|
* selector: "user-cmp",
|
2015-05-18 09:24:52 -07:00
|
|
|
* template: "User: {{ user | json }}"
|
|
|
|
* })
|
|
|
|
* class Username {
|
|
|
|
* user:Object
|
|
|
|
* constructor() {
|
|
|
|
* this.user = { name: "PatrickJS" };
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
*/
|
2015-06-22 17:11:55 -07:00
|
|
|
@CONST()
|
2015-10-27 10:18:29 +00:00
|
|
|
@Pipe({name: 'json', pure: false})
|
2015-08-06 10:39:02 -07:00
|
|
|
@Injectable()
|
2015-08-12 12:04:54 -07:00
|
|
|
export class JsonPipe implements PipeTransform {
|
2015-08-28 11:29:19 -07:00
|
|
|
transform(value: any, args: any[] = null): string { return Json.stringify(value); }
|
2015-05-18 09:24:52 -07:00
|
|
|
}
|