I have an AngularJS controller; On the first load the data is not fetching from db
app.controller("ProductPopupController", function ($scope, $http, $mdDialog, $filter) {
console.log("ProductPopupController");
var allGroups = [];
$http.get('UserDetail/GetAllUsers').success(function (response) {
console.log("I got the data I requested");
//console.log(response);
for (var i = 0; i < response.length; i++) {
allGroups.push({
UserName: response[i].UserName,
_id: response[i]._id
});
}
});
console.log(allGroups);
var allGroups = [
{ 'UserName': 'one', '_id': 1 },
{ 'UserName': 'two', '_id': 2 },
{ 'UserName': 'three', '_id': 3 },
{ 'UserName': 'four', '_id': 4 },
{ 'UserName': 'five', '_id': 5 },
{ 'UserName': 'six', '_id': 6 },
{ 'UserName': 'sixteen', '_id': 7 },
{ 'UserName': 'seven', '_id': 8 }
];
console.log(allGroups);
In this code I am getting the value from second array. Not getting from the db. After any event it will load from db. Whats wrong I have done here?
$http().success()and.errorhave been deprecated. They were helper methods that wrapped.thenand.catchand caused issues if you tried to use.successhalf way through a$httppromise chain..thenand.catchshould be used instead.