mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
refactor(common): log a warning when a JsonPipe receives a signal
The JsonPipe does not unwrap signals and `JSON.stringify` will return `undefined` for signals.
To avoid confusion, we log a warning when a signal is passed to the pipe.
(cherry picked from commit 0d652ba4da)
This commit is contained in:
committed by
Jessica Janiuk
parent
b5eea233df
commit
3c4deaa52b
@@ -6,7 +6,7 @@
|
||||
* found in the LICENSE file at https://angular.dev/license
|
||||
*/
|
||||
|
||||
import {Pipe, PipeTransform} from '@angular/core';
|
||||
import {isSignal, Pipe, PipeTransform} from '@angular/core';
|
||||
|
||||
/**
|
||||
* @ngModule CommonModule
|
||||
@@ -34,6 +34,10 @@ export class JsonPipe implements PipeTransform {
|
||||
* @param value A value of any type to convert into a JSON-format string.
|
||||
*/
|
||||
transform(value: any): string {
|
||||
if (ngDevMode && isSignal(value)) {
|
||||
console.warn(`The JsonPipe does not unwrap signals. Received a signal with value:`, value());
|
||||
}
|
||||
|
||||
return JSON.stringify(value, null, 2);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user