Angularjs 使用ng资源捕获自定义方法放置成功

Angularjs 使用ng资源捕获自定义方法放置成功,angularjs,put,ngresource,Angularjs,Put,Ngresource,我创建了一个自定义方法更新,方法类型为put 我想抓住成功的机会,在那里举办一些活动 有人知道怎么做吗 服务 (function () { 'use strict'; // this function is strict... angular .module('zdma.organization.services', []) .factory('Organization', function($resource, Config) { var Organizat

我创建了一个自定义方法更新,方法类型为put

我想抓住成功的机会,在那里举办一些活动

有人知道怎么做吗

服务

(function () {
'use strict';
 // this function is strict...

angular
    .module('zdma.organization.services', [])
   .factory('Organization', function($resource, Config) {

        var Organization = $resource(
                Config.url.organization + '/:id',
            {
                id: '@id' 
            },
            {
                'update': {
                    method: 'PUT'
                }
            }
        );

        // class methods
        Organization.getEmptyOrganizationTemplate = function () {
            return {
                'id': '',
                'name': '',
                'declarationCode': '',
                'website': ''
            };
        };
        return Organization;
    });
}());
内部控制器

angular
    .module('zdma.organization.controllers', [])
.controller('OrganizationCreateCtrl', function($scope, $location, Organization) {
    function init() {
        $scope.organization = new Organization(Organization.getEmptyOrganizationTemplate());
    }

    $scope.save = function() {   
        $scope.organization.$save();
    };
init();
});
你能帮我在这种情况下怎么做吗


请假设我的模型基于视图更新

控制器

angular.module('zdma.organization.controllers', [])
.controller('OrganizationCreateCtrl', function($scope, $location, Organization) {
    function init() {
        $scope.organization = new Organization(Organization.getEmptyOrganizationTemplate());
    }
    $scope.save = function() {   
        $scope.organization.$update(
           /* this function will be fired if you have a success */ 
           function(data){
               /* Put your events here */
           },
           /* this funciton will be fired if you have a failure */
           function(error){}
        );
    };
    init();
});

更新了我的问题,请有一个look@AdityaSethi希望有帮助。我正在使用正确的注射方法。我已在控制器中注入组织服务。为什么我不能使用$scope.organization=新组织($scope.editModel);然后用回调应用更新?我无法实际获取更新方法:($scope.organization.$update();工作正常,但只能使用刷新。这就是为什么我只想在无法找到的成功情况下重定向我的页面:(替换:$scope.organization.$update();使用:$scope.organization.update({},{},函数(数据){/*将代码放入her/},函数(错误){/把你的代码放在她身上*/);@AdityaSethi像这样。