我创建了一个方法类型为put的自定义方法更新。
我想抓住成功并在那里发动一些事件。
有没有人有公平的想法怎么做?
SERVICE
(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();
});
在这种情况下,你能帮我解决这个问题吗?
请假设我的模型在视图的基础上更新
答案 0 :(得分:0)
<强>控制器强>
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();
});