AngularJS error: fnPtr is not a function

前端 未结 2 354
孤街浪徒
孤街浪徒 2020-12-16 12:26

I\'m trying to write a sample AngularJS, and SpringMVC project. The spring methods works fine, but I have a problem with declaraton of function in my site controller. My app

相关标签:
2条回答
  • 2020-12-16 12:46

    I have tested your code. Using AngularJS 1.0.7, the error disappears when you replace

    $scope.send = new function() {
    

    with

    $scope.send = function () {
    

    and same applies to fetchList.

    I guess you mixed the two syntaxes function(*args*) { *body* } and new Function(*args*, *body*). Check on MDN: Function.

    You have also to change your code in order to get your fetchList properly called:

    function theNamer($scope, $http) {
    
            $scope.myName = 'aa';
    
            $scope.fetchList = function() {
    
                $http.get('ca/list.json').success(function(thList) {
    
                    $scope.names = thList;
    
                });
    
            };
    
            $scope.send = function() {
    
                $http.post('ca/set/3').success(function() {
    
                    $scope.fetchList();
    
                });
    
            };
    
            $scope.fetchList();
    
    }
    
    0 讨论(0)
  • 2020-12-16 13:01

    Just wanted to add for anybody receiving this error, it can also be seen if you, like me, make the n00b mistake of creating a variable with the same name as function (the function being called from ng-click:

    $scope.addTask = {};
    
    $scope.addTask = function() {};
    
    0 讨论(0)
提交回复
热议问题