【问题标题】:angular resource save sometimes converts int to string角度资源保存有时会将 int 转换为字符串
【发布时间】:2017-09-20 10:45:53
【问题描述】:

在控制器中,

$scope.save = function(obj) {
    restService.save(
        {table: "relations", id: obj.id}, obj
    )
}

在服务中,

.service('restService', ['$resource', function($resource){
    var prefixUrl = "http://localhost:4507/v1/rest";
        {
            table: "@table",
            id: "@id"
        },
        {
            query: {
                method: "GET",
            },
            save: {
                method: "PUT",
            },
            delete: {
                method: "DELETE",
            }
        }
    );
}])

当我调用 save 时,在 obj 中更改了整数值,它会自动转换为字符串。

您可以在第一张图片中看到 news_count: 0,但是当我将其值更改为 120 并再次发出请求时,$resource 似乎将其更改为“120”而不是 120。

为什么会这样?

【问题讨论】:

标签: angularjs


【解决方案1】:

“obj”是否与 绑定?来自的值应始终为字符串。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-29
    • 2011-10-02
    • 2011-03-06
    • 1970-01-01
    相关资源
    最近更新 更多