How do i call function that already declared in angularjs controller? -
i have defined function in angularjs controller. if call somewhere in 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 above code $scope.update();
not working. have searched many things in google have called in same way in case it's not working. don't know wrong.
as @svarog said have call function before declaration of it, try this.
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 = 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'); }); }; $scope.update(); }
Comments
Post a Comment