angularjs - Angular 资源在发布后清除对象数据

标签 angularjs ngresource

我的 Angular 应用程序在发布后清除数据。

这是来自 Controller 的片段:

$scope.saveDevice = function() {
            var deviceId = $scope.device.id;
            if (deviceId) {
                $scope.device.$update(function(result) {
                    $location.path('/devices');
                });
            } else {

                $scope.device.$save().then(function (deviceResult) {
                    $scope.device.id = deviceResult.deviceId;
                    $scope.device.$activationCode(function (result) {
                        $scope.device.activationCode = result.activationCode;
                    });
                });
            }
        };

当我到达断点时 "$scope.device.$save().then(function (deviceResult) {"应用程序显示设备中填充了来自表单的属性。但是在发布之后,设备的任何属性都被清除了。这是正常行为吗?如果是这样,我该如何预防?

最佳答案

在这里我找到了问题的答案:

AngularJS - Prevent Form Clear

基本上:

调用类方法

Device.save($scope.device)//....

代替

$scope.device.$save

它会保留你在 $scope.device 类中的数据。

关于angularjs - Angular 资源在发布后清除对象数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27446053/

相关文章:

javascript - AngularJs 指令更新

javascript - 加载所有异步数据和图像后滚动到 anchor

angularjs - 使用 angularJS 中的 $resource 将 id 发送到 DELETE API

angularjs - Chrome 上的未捕获对象错误。 Angularjs + ngResource

javascript - 使用 angularJS 结合 ui-bootstrap datepicker 和 timepicker?

javascript - AngularJS - 具有特定 JSON 对象的自定义过滤器

javascript - 如何使用 angularjs、Django、Django Rest 框架更新模型

javascript - Ngresource指定不同的URL的get all和get one

angularjs - ngResource 和 Json API 规范

javascript - AngularJS $resource 的默认(通用)错误处理