Bug when trying to set dataset to the result returned by promise
See original GitHub issueI 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:
- Created 7 years ago
- Reactions:1
- Comments:8 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 initdataset2
:Let me know if this helps
Hi @aligit can you check the
result
object if it actually contains something? Maybe you could even add an if-statement to only setdataset2
if result exists.Can you show your other options as well? Maybe you defined
dataset2
already before it is loaded.Best, Christoph