0

I created a function on my controller in angularjs which look likes this

$scope.pload = function () {
            $http.get('/WebServices/manageuser.asmx/showdatamanageuser', {
            }).then(function (response) {
                $scope.getdata = response.data;
                console.log($scope.getdata);
            });
        }

and i want to call this function after insert,delete and page load, so i called the function like this

<script type="text/javascript">
var app = angular.module("myApp", ["ngStorage"]);
app.controller("myCtrl", function ($scope, $http, $interval, $localStorage, $sessionStorage, $window) {
    var filename = undefined;
    var file = undefined;
    var filepath = undefined;

    //showing table

    $scope.pload();

the error i am getting is

TypeError: $scope.pload is not a function
    at new <anonymous> (VM190 ManageUser:427)
    at Object.invoke (angular.js:4842)
    at R.instance (angular.js:10695)
    at n (angular.js:9572)
    at g (angular.js:8881)
    at angular.js:8746
    at angular.js:1843
    at m.$eval (angular.js:17972)
    at m.$apply (angular.js:18072)
    at angular.js:1841

what is wrong here?

2
  • Where do you "call" the function from? Commented Feb 9, 2017 at 8:56
  • 1
    Well for what I can see in your ctrl it looks like you are calling the function before it is defined. The function call should be after the function is defined Commented Feb 9, 2017 at 9:00

2 Answers 2

1

Missing declare $scope in angular.module. Example :

angular.module('Appcontrollers', []).controller('LoginController', ['$rootScope', '$scope', '$http', function ($rootScope, $scope, $http,) {}
Sign up to request clarification or add additional context in comments.

Comments

0

You need to call the function after its definition not before like this :

$scope.pload = function () {
        $http.get('/WebServices/manageuser.asmx/showdatamanageuser', {
        }).then(function (response) {
            $scope.getdata = response.data;
            console.log($scope.getdata);
        });
    }

$scope.pload();

Comments