1

I make a example of directive in angular js .I am using this directive https://github.com/ONE-LOGIC/ngFlowchart

when I take static data ..it show the output please check my plunker http://plnkr.co/edit/d2hAhkFG0oN3HPBRS9UU?p=preview

but when I use $http request and make same json object .it not display the chart see my plunker using $http request .I have same data object as in static

http://plnkr.co/edit/Vts6GdT0NNudZr2SJgVY?p=preview

$http.get('data.json').success(function(data) {
        console.log(data)
        var arr = data
        var model={};

        var new_array = []
        for (var i = 0; i < arr.length; i++) {
            var obj = {};
            obj.name = arr[i].name;
            obj.id = arr[i].id;
            obj.x = arr[i].x;
            obj.y = arr[i].y;
            obj.color = '#000';
            obj.borderColor = '#000';
            var p = {};
            p.type = 'flowchartConstants.bottomConnectorType';
            p.id = arr[i].con_id
            obj.connectors = [];
            obj.connectors.push(p);
            new_array.push(obj);

        }
        console.log('new array')
        console.log(new_array)
          model.nodes=new_array;


        var edge = [];
        for (var i = 0; i < arr.length; i++) {
            if (arr[i].children.length > 0) {

                for (var j = 0; j < arr[i].children.length; j++) {
                    var obj = {};
                    obj.source = arr[i].con_id;
                    obj.destination = arr[i].children[j].con_id;
                    edge.push(obj);
                }

            }

        }
          model.edges=edge;
        console.log(edge)
        console.log("model")
          console.log(JSON.stringify(model))
          $scope.flowchartselected = [];
      var modelservice = Modelfactory(model, $scope.flowchartselected);

    $scope.model = model;
    $scope.modelservice = modelservice;

    })

any update ?

7
  • According to the Plunkr, your data is not found. Response code is 404 and response is: { "statusCode": 404, "error": "Not Found" } Since you only provide a .success() (which, by the way, is deprecated, consider switching to .then()), you can't catch the error. Commented Jan 20, 2016 at 3:53
  • Sorry i will update my plunker Commented Jan 20, 2016 at 3:59
  • plnkr.co/edit/Vts6GdT0NNudZr2SJgVY?p=preview Commented Jan 20, 2016 at 4:00
  • I'm looking into it, it may take a bit to fully understand the code before I can see the error. Commented Jan 20, 2016 at 4:23
  • 1
    got the solution thanks for help plnkr.co/edit/d2hAhkFG0oN3HPBRS9UU?p=preview Commented Jan 20, 2016 at 4:29

1 Answer 1

1

Working Example

It is now working.

The issue was when we load the directive first time it has no parameter value to it. So, when the chart directive try to initialize your chart with no parameter it gets an error. So, it will not work anymore.

How solve the issue?

Just give a dummy parameter upon the page load. I have given the dummy model as,

 $scope.model = model;
 $scope.modelservice = modelservice;

So, first your chart will display a chart based on the dummy values. After that it populates chart with the data from the server ($http.get())

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.