Why can I not use something like this?
<input type="text" ng-model="testVal">
<pre>{{JSON.stringify(testVal,null,4)}}</pre>
If I remove the JSON.stringify() method my code works just fine.
The double brackets syntax {{something}} tells angular to look in the $scope object for a match.
So {{name}} matches to $scope.name set in your controller.
You can use methods in here (and I would recommend it to keep your view files clean) and this will resolve your problem.
So in the controller:
$scope.stringify = function(value, replacer, space)
{
return JSON.stringify(value,replacer,space);
}
... then in your view:
<pre>{{stringify(testVal,null,4)}}</pre>
You can simply use | json :
{{ testVal | json }}
or add JSON to $scope :
$scope.JSON = JSON
then
<pre>{{ JSON.stringify(testVal) }}</pre>
works