Javascript 角度承诺-提交时获取“错误:args为null$parseFunctionCall”
我目前正在MEAN.js上学习这首芭蕾舞曲: 我被困在接线的末端,我对angular完全陌生,所以我没有假装我理解我所做的一切。情况如下: 我们正在使用插件ui路由器 首先是html模板:Javascript 角度承诺-提交时获取“错误:args为null$parseFunctionCall”,javascript,angularjs,angular-ui-router,angular-promise,Javascript,Angularjs,Angular Ui Router,Angular Promise,我目前正在MEAN.js上学习这首芭蕾舞曲: 我被困在接线的末端,我对angular完全陌生,所以我没有假装我理解我所做的一切。情况如下: 我们正在使用插件ui路由器 首先是html模板: <form name="addComment" ng-submit="addComment.$valid && addComment()"novalidate> <div class="form-group"> <input class="
<form name="addComment" ng-submit="addComment.$valid && addComment()"novalidate>
<div class="form-group">
<input class="form-control" type="text" placeholder="Comment" ng-model="body" required/>
</div>
<button type="submit" class="btn btn-primary">Comment</button>
</form>
这里是控制器:
app.controller('PostsCtrl', ['$scope', 'posts', 'post',
function ($scope, posts, post) {
$scope.post = post;
$scope.addComment = function () {
posts.addComment(post._id, {
body : $scope.body,
author: 'user'
}).success(function (comment) {
$scope.post.comments.push(comment);
});
$scope.body = '';
};
$scope.incrementUpVote = function (comment) {
posts.upvoteComment(post, comment);
};
}]);
最后是从远程Web服务检索帖子的工厂
app.factory('posts', ['$http', function ($http) {
var o = {
posts: []
};
o.get = function (id) {
return $http.get('/posts/' + id).then(function (res) {
return res.data;
});
};
o.addComment = function (id, comment) {
return $http.post('/posts/' + id + '/comments', comment);
};
return o;
}]);
我只给出了我认为相关的部分
我怀疑问题出在已经解除联系的承诺和范围之外。我搜索过承诺,但我认为ui路由器的做法有所不同
我在控制器中尝试了一些$watch,但没有成功
有人知道吗?提前感谢用于addComment的表单名addComment。$valid和添加到作用域的函数addComment相互冲突,请重命名其中一个 有关form指令,请参见: 如果指定了name属性,则发布表单控制器 此名称下的当前作用域
由于您还手动添加了一个名为addComment的函数,因此在评估ng submit时使用了错误的函数。在您的工厂中,您没有返回承诺。您能否在plunker或同等版本中重现该错误?
app.factory('posts', ['$http', function ($http) {
var o = {
posts: []
};
o.get = function (id) {
return $http.get('/posts/' + id).then(function (res) {
return res.data;
});
};
o.addComment = function (id, comment) {
return $http.post('/posts/' + id + '/comments', comment);
};
return o;
}]);