Skip to content

Instantly share code, notes, and snippets.

@shaunxu
Created January 9, 2015 04:27
Show Gist options
  • Save shaunxu/a8508bfd12a6826a820d to your computer and use it in GitHub Desktop.
Save shaunxu/a8508bfd12a6826a820d to your computer and use it in GitHub Desktop.
Demo on how to use ui-json-editor
<!DOCTYPE html>
<html ng-app="MyApp">
<head>
<link rel="stylesheet" href="jsoneditor.css" />
</head>
<body>
<h1>Hello AngularJS-JSONEditor</h1>
<div ng-controller="MyCtrl">
<div data-ui-json-editor data-ng-model="json"></div>
<pre>{{json | json}}</pre>
</div>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular.js"></script>
<script src="jsoneditor.js"></script>
<script src="ui.jsoneditor.js"></script>
<script>
var app = angular.module('MyApp', ['ui.jsoneditor']);
app.config(['jsoneditorOptionsProvider',
function(jsoneditorOptionsProvider) {
jsoneditorOptionsProvider.setOptions({
name: 'root',
modes: ['text', 'tree']
});
}
]);
app.controller('MyCtrl', function($scope) {
$scope.editor = {};
$scope.json = {
firstName: 'Shaun',
lastName: 'Xu',
skills: [
'C#',
'JavaScript'
],
roles: [
'dev',
'speaker'
]
};
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment