I have already defined a function in angularjs controller. But if I call it from somewhere in the same controller it's not working.
controller.js
function ManageProductController($http, $scope, $mdDialog, $document, $location, $localStorage)
{
var vm = this;
vm.uid = $localStorage._id;
vm.purchased = '';
$scope.Types = [{code:1, type:'Available Items'}, {code:2, type:'Purchased Items'}, {code:3, type:'Guest Contributed'}, {code:4, type:'Full List'}];
$scope.update();
$scope.update = function() {
if($scope.selectedCode == 1){
vm.purchased = "yes";
}else if($scope.selectedCode == 2){
vm.purchased = "";
}else{
vm.purchased = "no";
}
$http({
url: 'http://localhost:7200/api/manage-product',
method: 'POST',
data: {userId:vm.uid, code:vm.purchased}
}).success(function(res) {
//$scope.productlist = res;
//console.log(vm.result);
vm.result = res.result;
vm.count=vm.result.length;
//console.log(vm.result);
if(vm.count == 0){
vm.showMessage = true;
} else {
vm.result=res.result;
vm.showMessage = false;
}
//console.log(vm.result);
//vm.docs=res.docs;
}, function(error) {
console.log(error);
alert('here');
});
};
}
In the above code $scope.update(); is not working. I have searched so many things in google but they have called in the same way but in my case it's not working. I don't know where am i wrong.
$scope.update();? you call it before you declare it