ui-ace icon indicating copy to clipboard operation
ui-ace copied to clipboard

JSON Stringify on Arrays and Objects

Open kirstein opened this issue 12 years ago • 3 comments

Is there some specific reason why the ui-ace throws an exception when we are dealing with array or object types? At the first glance it seems perfectly safe to just stringify those types. Am I missing something?

Just wanted to hear your opinion about stringifying those before I submitted a PR.

kirstein avatar Oct 20 '13 21:10 kirstein

Is there some specific reason why the ui-ace throws an exception when we are dealing with array or object types?

Talking about the error ui-ace cannot use an object or an array as a model ? For me it's because you're not supposed to use those types of values on the Document.setValue method. And like the ngModel is only reflecting the editor content it must be a string.

At the first glance it seems perfectly safe to just stringify those types. Am I missing something? Just wanted to hear your opinion about stringifying those before I submitted a PR.

I really think that it's a uncommon issue that isn't supposed to be directly allowed. Ace is just a code editor. It gives and takes code as text.

douglasduteil avatar Oct 30 '13 08:10 douglasduteil

There will be nice to have it for cases where you want to "edit" in the ace editor code an attribute of your model in JSON format.

diegopamio avatar May 15 '15 19:05 diegopamio

What I've done is to have a different scope attribute, which gets updated by watching the model, and it's the string representation of the object.

$scope.$watch('', function (newValue) { $scope.<your model's>source = JSON.stringify(newValue, null, 2); }, true);

diegopamio avatar May 15 '15 19:05 diegopamio