如何从angularjs-rails-resource获取create()、update()上的确认或回调
How to get a confirmation or callback from angularjs-rails-resource on create(), update()
我正在使用AngularJs Rails资源,并且想知道当您使用create()
或update()
方法成功创建/更新资源时是否有回调。
$scope.createPage = function () {
var page = new Page({
title: $scope.pageTitle,
content: $scope.pageContent,
published: true
});
if (page.create()){
$scope.showAlert('Page created successfully', 'success');
} else {
$scope.showAlert('There was a problem creating the page.', 'warning');
}
}
但这不起作用。即使API不可用,也会创建成功消息。
任何想法?
你应该使用Using resources:
$scope.createPage = function () {
var page = new Page({
title: $scope.pageTitle,
content: $scope.pageContent,
published: true
});
page.create().then(function (results) {
console.log(results);
$scope.showAlert('Page created successfully', 'success');
}, function (error) {
console.log(error);
$scope.showAlert('There was a problem creating the page.', 'warning');
});
}
相关文章:
- AngularJS:我可以跳过函数参数回调吗
- 要求未定义JS回调参数
- MeteorJS:在带有回调的vzaar api上正确使用wrapAsync
- 自引用回调
- 测试Angular Service解决错误回调中的promise
- 如何将一个JavaScript函数回调为多个函数
- JavaScript回调函数
- 用于回调的javascript参数
- 将json回调数据转换为日期
- 承诺在非节点式回调上使用Bluebird
- 如何在回调函数中执行流
- 回调函数中传递参数的困难(Google Map API Markers)
- Soundcloud Javascript SDK 3.0-回调无法读取属性'connectCallback
- 如何使用jqueryAJAX从页面中回调多个变量
- Bootstrap3确认模式回调触发两次
- 如何在jquery确认对话框中使用回调
- 通知.确认回调未触发电话间隙 iOS
- 用于确认引导框的Javascript回调函数
- 在onbeforeunload事件的窗口确认时调用回调函数
- 如何从angularjs-rails-resource获取create()、update()上的确认或回调