2016-06-23 09:47:54 -07:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2019-04-11 15:39:29 +02:00
|
|
|
import {Injectable, Pipe, PipeTransform} from '@angular/core';
|
2016-06-08 16:38:52 -07:00
|
|
|
|
2015-05-18 09:24:52 -07:00
|
|
|
/**
|
2016-09-08 21:41:09 -07:00
|
|
|
* @ngModule CommonModule
|
|
|
|
* @description
|
|
|
|
*
|
2018-05-25 14:44:33 -07:00
|
|
|
* Converts a value into its JSON-format representation. Useful for debugging.
|
2015-05-18 09:24:52 -07:00
|
|
|
*
|
2018-05-25 14:44:33 -07:00
|
|
|
* @usageNotes
|
|
|
|
*
|
|
|
|
* The following component uses a JSON pipe to convert an object
|
|
|
|
* to JSON format, and displays the string in both formats for comparison.
|
2016-05-27 11:24:05 -07:00
|
|
|
*
|
2018-05-03 09:38:05 +01:00
|
|
|
* {@example common/pipes/ts/json_pipe.ts region='JsonPipe'}
|
2018-04-05 22:31:44 +01:00
|
|
|
*
|
2018-10-19 15:06:08 +01:00
|
|
|
* @publicApi
|
2015-05-18 09:24:52 -07:00
|
|
|
*/
|
2019-04-11 15:39:29 +02:00
|
|
|
@Injectable()
|
2015-10-27 10:18:29 +00:00
|
|
|
@Pipe({name: 'json', pure: false})
|
2015-08-12 12:04:54 -07:00
|
|
|
export class JsonPipe implements PipeTransform {
|
2018-05-25 14:44:33 -07:00
|
|
|
/**
|
|
|
|
* @param value A value of any type to convert into a JSON-format string.
|
|
|
|
*/
|
2016-10-19 13:42:39 -07:00
|
|
|
transform(value: any): string { return JSON.stringify(value, null, 2); }
|
2015-05-18 09:24:52 -07:00
|
|
|
}
|