GithubHelp home page GithubHelp logo

Comments (6)

doingweb avatar doingweb commented on September 13, 2024 1

I've observed that this issue will not occur when starting in tree mode, then switching to code mode. It does occur when defaulting the mode to code.

Not sure if it makes a difference, but I am passing in my model as an object (not JSON string).

from ng-jsoneditor.

angular-tools avatar angular-tools commented on September 13, 2024

data must be passed as ng-model.

see this code: http://jsfiddle.net/angulartools/sd3at5ek/

from ng-jsoneditor.

franza avatar franza commented on September 13, 2024

Thanks for your response.

In the example that I provided to you in jsfiddle, data is passed as ng-model like in your example:

<div ng-jsoneditor="onLoad" ng-model="obj.data" options="obj.options" style="width: 400px; height: 300px;"></div>

Also, obj was added to the $scope as in your example:

$scope.obj = {data: json, options: {mode: 'code'}};

The only difference is that I would like that editor will start in "code" mode instead of "tree". If you simply change mode in your example to code, then editor will display an empty object.

from ng-jsoneditor.

wisza avatar wisza commented on September 13, 2024

I have the same problem. It is working when I open page first time and not for second and next times. First time I download json data from service so it takes some time. After refresh it gets data quickly (probably from cache) and it fails because when I set value of my model editor is not loaded.

I fixed problem by waiting with assigning value to model until editor is initialized.

I do something like this:

<div data-ng-jsoneditor="onEditorLoad" data-ng-model="definition" options="{ mode: 'code' }" class="editor"></div>

 $scope.onEditorLoad = function (instance) {
   $scope.editor = instance;
 };

var setEditorData = function (data) {
  if ($scope.editor) {
    $scope.definition = data;
  }
  else {
    $timeout(function() { setEditorData(data) }, 250);
  }
}

I think this should be done inside component. So component itself should check if editor is loaded and if not wait before process with model value.

from ng-jsoneditor.

ptrussart avatar ptrussart commented on September 13, 2024

Hello,

Did you find a way to solve this problem ? I have the issue everytime I use the "code" mode. Tree view works fine but "code" always displays an empty object.

from ng-jsoneditor.

HelloJasonZhang avatar HelloJasonZhang commented on September 13, 2024

Using $interval to fixed 'code' mode
$interval(function() {
vm.obj.data = data
}, 200,1);

from ng-jsoneditor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.