I have this Angular code, which is giving me an error on the line with:
vm.lps.sort()
(() => {
angular
.module('app')
.controller('appController', appController)
appController.$inject = ['$http', '$scope', '$rootScope'];
function appController ($http,$scope, $rootScope) {
let vm = this;
$http.get('/user/username/').then(function(response){
vm.names = response.data.lps;
})
//Sort the array
vm.names.sort();
..................
..................
}
})()
and the error is:
Cannot read property 'sort' of undefined
at new appController
Why is it happening ?