panelApp.directive('batJsonTree', function($compile) { return { restrict: 'E', terminal: true, scope: { val: '=' //edit: '=', }, link: function (scope, element, attrs) { // this is more complicated then it should be // see: https://github.com/angular/angular.js/issues/898 var buildDom = function (object) { var html = ''; if (object == undefined) { html += 'null'; } else if (object instanceof Array) { var i; html += '
['; for (i = 0; i < object.length; i++) { html += buildDom(object[i]) + ', '; } html += ']
'; } else if (object instanceof Object) { for (prop in object) { if (object.hasOwnProperty(prop)) { html += '
' + prop + ': ' + buildDom(object[prop]) + '
'; } } } else { html += '' + object.toString() + ''; } return html; }; scope.$watch('val', function (newVal, oldVal) { element.html(buildDom(newVal)); }); } }; });