I create an Angular / Express application, load data using a controller and try to work with data in a function, but I get an error in the console
Unable to read property 'toLowerCase' undefined
When I manually write JSON data, it works fine. Someone had this error and why is this happening?
Edit: I also want the function to work on click when I want it not to load, I also use data from listData , so I know that it is loaded
controller
var self = this; self.listData = []; var self = this; self.listData = []; $http.get('/myList') .success(function (data) { self.listData = data; console.log(data); }) .error(function (data) { console.log('Error: ' + data); }); self.myFunc = function(){ var map = self.listData.reduce(function (p, c) { p.set(c.name.toLowerCase(), c.surname); return p; }, new Map()); console.log(...map); }
json javascript angularjs ajax
Absolute beginer
source share