AngularJS error: fnPtr is not a function

前端 未结 2 372
孤街浪徒
孤街浪徒 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();
    
    }
    

提交回复
热议问题