Javascript 即使未在HTML中显式调用,也会通过$request发出post请求
我正在学习有关的教程 这是我的控制器:Javascript 即使未在HTML中显式调用,也会通过$request发出post请求,javascript,angularjs,function,closures,Javascript,Angularjs,Function,Closures,我正在学习有关的教程 这是我的控制器: app.controller('PostsCtrl', function ($scope, Post){ $scope.posts = Post.get(); $scope.post = {url: 'http://', title: ''}; Post.save($scope.post, function (ref) { $scope.posts[ref.name] = $scope.post; //$scope.post = {url: 'ht
app.controller('PostsCtrl', function ($scope, Post){
$scope.posts = Post.get();
$scope.post = {url: 'http://', title: ''};
Post.save($scope.post, function (ref) {
$scope.posts[ref.name] = $scope.post;
//$scope.post = {url: 'http://', title: ''};
});
$scope.submitPost = function () {
Post.save($scope.post);
//$scope.post = {url: 'http://', title: ''};
};
$scope.deletePost = function (postId) {
Post.delete({id: postId}, function () {
delete $scope.posts[postId];
});
};
}))
以下是HTML:
<div ng-repeat="(postId, post) in posts">
<a href="{{post.url}}">{{post.title}}</a>
<a ng-click="deletePost(postId)">delete</a>
</div>
<!--<form ng-submit="submitPost()">-->
<!--<input type="text" ng-model="post.title" />-->
<!--<input type="text" ng-model="post.url" />-->
<!--<input type="submit" value="Add Post" />-->
<!--</form>-->
Posts: {{ posts }}<br />
Post: {{ post }}
这可能是因为您调用了Post.save()
。你试过把它评论出来吗?我是个笨蛋。哈哈。谢谢