복붙노트

[SPRING] AngularJS 오류 : fnPtr은 함수가 아닙니다.

SPRING

AngularJS 오류 : fnPtr은 함수가 아닙니다.

샘플 AngularJS 및 SpringMVC 프로젝트를 작성하려고합니다. 스프링 메서드는 잘 작동하지만 내 사이트 컨트롤러의 함수 선언에 문제가 있습니다. 내 애플 리케이션은 텍스트 입력에서 단어를 반환해야하지만, 버튼을 클릭하면, 나는이 오류가있어 :

[13:23:58.900] "Error: fnPtr is not a function
parser/_functionCall/<@http://localhost:8080/example/resources/js/Angular/angular.js:6542
ngEventDirectives[directiveName]</</</<@http://localhost:8080/example/resources/js/Angular/angular.js:13256
Scope.prototype.$eval@http://localhost:8080/example/resources/js/Angular/angular.js:8218
Scope.prototype.$apply@http://localhost:8080/example/resources/js/Angular/angular.js:8298
ngEventDirectives[directiveName]</</<@http://localhost:8080/example/resources/js/Angular/angular.js:13255
createEventHandler/eventHandler/<@http://localhost:8080/example/resources/js/Angular/angular.js:2095
forEach@http://localhost:8080/example/resources/js/Angular/angular.js:130
createEventHandler/eventHandler@http://localhost:8080/example/resources/js/Angular/angular.js:2094
"

이것은 내 index.html입니다 :

<!DOCTYPE html>
<html lang="en" ng-app="Apken">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="resources/js/Angular/angular.js"></script>
<script src="resources/js/controler.js"></script>

</head>
<body ng-controller="theNamer">

<div class="input-append">
    <input style="width:358px;" class="span2" type="text" ng-model="myName" required min="1" />
    <button class="btn btn-primary" ng-disabled="!myName" ng-click="send()">Click!</button>
</div>
<ul>
<li  ng-repeat="name in names">{{name}}</li>

</ul>

</body>
</html>

그리고 controller.js :

function theNamer ($scope,$http){
    $scope.myName='aa';

    $scope.fetchList=new function()
    {
        $http.get('ca/list.json').success(function(thList){
            $scope.names = thList;
        });
    }

        $scope.send=new function()
        {

            $http.post('ca/set/3').success(function(){

            $scope.fetchList;

            });

        }
        $scope.fetchList;


}

var Apken = angular.module('Apken',[]);
Apken.controller('theNamer', theNamer);

나는 그것이 ng-click 값에서 함수 선언과 관련하여 어떤 종류의 문제 여야 만한다는 것을 알았다. 사이트 시작시 controler.js는 정상적으로 작동하지만 버튼을 클릭하면 충돌이 발생합니다.

해결법

  1. ==============================

    1.나는 당신의 코드를 테스트했다. AngularJS 1.0.7을 사용하면 대체 할 때 오류가 사라집니다.

    나는 당신의 코드를 테스트했다. AngularJS 1.0.7을 사용하면 대체 할 때 오류가 사라집니다.

    $scope.send = new function() {
    

    $scope.send = function () {
    

    fetchList에도 동일하게 적용됩니다.

    (* args *) {* body *}와 새로운 Function (* args *, * body *) 구문을 혼합했다고 생각합니다. MDN : 기능을 확인하십시오.

    fetchList를 제대로 호출 할 수 있도록 코드를 변경해야합니다.

    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();
    
    }
    
  2. ==============================

    2.이 오류를받는 사람을 추가하기를 원했을 때, 나처럼, 함수와 동일한 이름을 가진 변수를 만드는 n00b 실수를 저지르는 경우 (ng-click에서 호출되는 함수 :

    이 오류를받는 사람을 추가하기를 원했을 때, 나처럼, 함수와 동일한 이름을 가진 변수를 만드는 n00b 실수를 저지르는 경우 (ng-click에서 호출되는 함수 :

    $scope.addTask = {};
    
    $scope.addTask = function() {};
    
  3. from https://stackoverflow.com/questions/19208518/angularjs-error-fnptr-is-not-a-function by cc-by-sa and MIT license