angular-ui / ui-ace

This directive allows you to add ACE editor elements.
http://angular-ui.github.io/ui-ace
MIT License
578 stars 172 forks source link

JSON Stringify on Arrays and Objects #15

Open kirstein opened 10 years ago

kirstein commented 10 years ago

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.

douglasduteil commented 10 years ago

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.

diegopamio commented 9 years ago

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 commented 9 years ago

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);