0

I found many similar questions but I couldn't apply the solutions to my problem.

So in my angular app I am drawing nvd3 charts.

I am doing a get request in the service and I can see from the network in my browser that I am ALWAYS getting the chart data as I am supposed to.

The problem is that, when I am running grunt serve to start my angular app, I am still getting the data through the api, but for some reason they are not shown.

That just happens only when I run grunt serve. However, if I hit refresh, after running grunt serve, the data are shown correctly.

Thanks in advance for any help.

this is what I am trying to do:

'use strict';

angular.module('myApp')
.service('mainService', function($http) {
  this.getData = function() {
    return $http({
      method: 'GET',
      url: '/rest/api/config',
    });
  }
})
.controller('MainCtrl', function($scope, $http, mainService) {
  var name = 'main';
  var model; 

  mainService.getData().then(function(d) {
    model = d.data;
    $scope.modelling();
  });

  $scope.modelling = function() {
    if(!model) {
      console.log("no model");
      // set default model for demo purposes
      model = {
        title: "about",
        structure: "12/4-4-4",
    };
  }

  console.log(model);
  $scope.name = name;
  $scope.model = model;
  $scope.collapsible = true;
  }
});
Nicolas Nicolas
  • 225
  • 2
  • 15

1 Answers1

0

Try something like this. Initially, in your example, $scope.model is going to be undefined.


.controller('MainCtrl', function($scope, $http, mainService) {
  var name = 'main';

mainService.getData().then(function(d) { $scope.modelling(d.data); });

$scope.modelling = function(data) { //do something with data here, or set $scope.model = data; }

$scope.name = name; $scope.collapsible = true; } });

That might work, depends on how you set up the nvd3 charts.
reptilicus
  • 10,290
  • 6
  • 55
  • 79