0

I am currently developing a little app with Angular and MEAN.js. I would like to plot a D3 chart with some real data coming from the model. To do so, I would have to read from the $scope.campaign variable and initialize the $scope.dataBarChart with the data from $scope.campaign.tokens that is an array.

// Find existing Campaign
$scope.findOne = function() {
    $scope.campaign = Campaigns.get({ 
        campaignId: $stateParams.campaignId
    });

    $scope.dataBarChart = [
        {
        'key': 'Token Requested',
        'values': [['10.10.2014', 550000], ['11.10.2014',300000]]
        }, {
        'key': 'Token Consumed',
        'values': [['10.10.2014', 250000], ['11.10.2014',200000]]
        }
    ];
};

When I try to log the value of $scope.campaign, I get all the data that I need. Unfortunately, when I try to access the $scope.campaign.tokens, I get an error like impossible to access tokens from undefined value. Basically, it seems that there is no data, but I know from the log that is not like this.

The complete code is simply the same, but with a console.log line

// Find existing Campaign
$scope.findOne = function() {
$scope.campaign = Campaigns.get({ 
   campaignId: $stateParams.campaignId
});

console.log($scope.campaign)

$scope.dataBarChart = [{
   'key': 'Token Requested',
   'values': [['10.10.2014', 550000], ['11.10.2014',300000]]
   }, {
   'key': 'Token Consumed',
   'values': [['10.10.2014', 250000], ['11.10.2014',200000]]
}];
};

The console.log shows the right content, but when I try to use it $scope.campaign.tokens, it says undefined.

Anyone suggestions? Thanks

5
  • 1
    Show us the code where you are logging scope.campaign and where you are accessing it. Commented Oct 6, 2014 at 19:49
  • What does Campaigns.get return? Commented Oct 6, 2014 at 19:49
  • Double check your DI asap! Commented Oct 6, 2014 at 19:52
  • @NoahMatisoff what do I have to check? Commented Nov 17, 2014 at 19:20
  • Dependency Injection. Commented Nov 17, 2014 at 19:41

1 Answer 1

1

Try

$scope.campaign.$promise.then(function(data) {
   console.log(data.tokens)
});
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.