Trying to implement JSON.stringify as explained here: Hide certain values in output from JSON.stringify() and exclude some fields from serialization but it doesn't work.
For example in my controller I've the following code:
.controller('ExampleController', ['$scope', function($scope) {
$scope.event = {
id:1,
title: 'event title',
users: [{
id: 1,
name: 'Anatoly'
},{
id: 2,
name: 'Roman'
}],
private1: 1,
private2: 2
};
var replacer = function(key, value){
console.log(key);
};
$scope.stringified1 = JSON.stringify($scope.event, replacer);
// $scope.stringified = JSON.stringify($scope.event, ['id','title','users','name']);
}]);
Why console.log(key)
prints nothing? The function itself is invoked, but key
parameter is empty.
I've done plunker here: http://plnkr.co/edit/U6ZcIuPVr5RzMIBl8X6c?p=preview
I'm using Angular 1.4.9 and Chrome 48.0.2564.116
P.S. I've done this functionality with passed array and it works, but using a function can give a much more flexibility so I'd like to understand why it doesn't work.