question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug when trying to set dataset to the result returned by promise

See original GitHub issue

I can successfully generate with predefined data. However when I try to dynamically add new dataset returned by the result of http.get the following error:

angular.js:13236 TypeError: Cannot read property 'values' of undefined.

this is my service:

  getValveChartData(type, trim, size, diameter_unit){
     return this.http.get("http://localhost:5685/api/values/getValveChart?type="+type+"&size="+size+"&trim="+trim+"&diameter_unit="+diameter_unit).then(result => result.data );
  }

In my controller:
    this.calculator.getValveChartData()
      .then(javab => {
        this.data = {
          dataset2: result
        };
};

If I replace result with some valid array it will generate the chart but I don’t know why the result will launch that error.

Thanks

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
chaosmailcommented, Apr 13, 2016

You are already defining dataset2 in the option, when the dataset is (most likely) not available (in the beginning). When you define your dataset, just init dataset2:

this.data = {
    ...
    'dataset2': []
}

Let me know if this helps

1reaction
chaosmailcommented, Apr 13, 2016

Hi @aligit can you check the result object if it actually contains something? Maybe you could even add an if-statement to only set dataset2 if result exists.

this.calculator.getValveChartData()
      .then(javab => {
        console.log(result);
        this.data = {
          dataset2: result
        };

Can you show your other options as well? Maybe you defined dataset2 already before it is loaded.

Best, Christoph

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is my asynchronous function returning Promise ...
My main goal is to get token from google.login(data.username, data.password) which returns a promise, into a variable. And only then preform ...
Read more >
Resolving the JavaScript Promise Error "TypeError: Cannot ...
In this guide, we will cover two code examples containing a bugs that cause this TypeError and then refactor the code to resolve...
Read more >
Javascript: How to access the return value of a Promise object
Let's see how we can access returned data. 1 - .then() chaining. It is the most simple and the most obvious way. fetch( ......
Read more >
Promise.prototype.then() - JavaScript - MDN Web Docs
returns an already rejected promise: p gets rejected with that promise's value as its value.
Read more >
How to create a function with a Promise and return data to be ...
I am trying to create a function which can perform an insert and return the response object from MongoDB, so I can take...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found