2015-06-22 17:11:55 -07:00
|
|
|
import {isBlank, isPresent, Json, CONST} from 'angular2/src/facade/lang';
|
2015-08-06 10:39:02 -07:00
|
|
|
import {Injectable} from 'angular2/di';
|
2015-08-07 11:41:38 -07:00
|
|
|
|
|
|
|
import {PipeTransform, WrappedValue, BasePipeTransform} from 'angular2/change_detection';
|
|
|
|
|
|
|
|
import {Pipe} from 'angular2/src/core/annotations/decorators';
|
2015-05-18 09:24:52 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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" };
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* ```
|
|
|
|
*/
|
2015-06-22 17:11:55 -07:00
|
|
|
@CONST()
|
2015-08-07 11:41:38 -07:00
|
|
|
@Pipe({name: 'json'})
|
2015-08-06 10:39:02 -07:00
|
|
|
@Injectable()
|
2015-08-07 11:41:38 -07:00
|
|
|
export class JsonPipe extends BasePipeTransform {
|
2015-07-07 20:03:00 -07:00
|
|
|
transform(value: any, args: List<any> = null): string { return Json.stringify(value); }
|
2015-05-18 09:24:52 -07:00
|
|
|
}
|