1
的我在我的服務器工作的API,我的CRUD模塊的工作就好了,我可以得到,POST,PUT,刪除我的服務器
我也有CRUD模塊在我的角度控制器,它除了刪除功能
我使用ngResource $保存,$更新,和$一切工作正常刪除爲客戶一路操縱數據到服務器
的$保存和$更新工作得很好,但$刪除retu RNS我的錯誤:「無法讀取的未定義的屬性$刪除」
這裏是我的控制器
$scope.findOne = function() {
$scope.post = Posts.get({
postId: $routeParams.postId
});
};
$scope.update = function() {
$scope.post.$update(function() {
$location.path('posts/' + $scope.post._id);
}, function (errorResponse) {
$scope.error = errorResponse.data.message;
});
};
$scope.delete = function (post) {
if (post) {
post.$remove(function() {
for (var i in $scope.posts) {
if ($scope.posts[i] === post) {
$scope.posts.splice(i, 1);
}
}
});
}
else {
$scope.posts.$remove(function() {
$location.path('posts');
});
}
};
我的服務
angular.module('posts').factory('Posts', ['$resource',
function ($resource) {
return $resource('posts/:postId', {
postId: '@_id'
}, {
update: {
method: 'PUT'
}
});
}
]);
奇怪的是,更新,工作,但在刪除不起作用
是否因爲我在刪除方法中的參數?
這裏是我的看法
<div data-ng-controller="PostsCtrl">
<section data-ng-init="findOne()">
<div data-ng-show="authentication.user._id === post.author._id">
<a href="/#!/posts/{{post._id}}/edit">Edit</a>
<a href="#" data-ng-click="delete()">delete</a>
</div>
</section>
</div>
爲什麼我無法刪除帖子,並返回undefined? $ ng是否不再用於ngResource?
ngResource中有哪些可用的方法?