AngularJS错误:fnPtr不是函数 [英] AngularJS error: fnPtr is not a function
问题描述
我想写一个样品AngularJS,用SpringMVC和项目。春方法工作正常,但我有一个问题,在我的网站控制器的功能declaraton。我的应用应当从文本输入返回一个字,但是当我按一下按钮,我得到这个错误:
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 should return a word from text input, but when I click the button, I've got this error:
[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:
This is my 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>
和controler.js:
And controler.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-点击值函数声明。在现场启动controler.js工作正常,但它崩溃,当我点击该按钮。
I've noticed, that must be a some kind of problem with function declaration in the ng-click value. On site startup controler.js works fine, but it crashes, when I click the button.
推荐答案
我已经测试了code。使用AngularJS 1.0.7,当您更换错误消失
I have tested your code. Using AngularJS 1.0.7, the error disappears when you replace
$scope.send = new function() {
与
$scope.send = function () {
和同样适用于 fetchList
。
我想你混合两种语法功能(* ARGS *){*身体*}
和新功能(* ARGS *,*体*)
。检查MDN:功能
I guess you mixed the two syntaxes function(*args*) { *body* }
and new Function(*args*, *body*)
. Check on MDN: Function.
您也纷纷改变你的code为了得到你的 fetchList
正常调用:
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();
}
这篇关于AngularJS错误:fnPtr不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!