【问题标题】:Angular throwing error with SafariSafari 的角度抛出错误
【发布时间】:2015-05-18 00:13:13
【问题描述】:

在 safari 上,angular 抛出一个奇怪的错误请求的键值不是对象。当我调用下面的函数时。它在 chrome 和 firefox 上运行良好,但在 safari 上却不是那么好。我什至调用了 console.log 来查看错误在哪里,以及 $scope.id 是否返回一个值以从该 ID 中提取所有其他数据......测试了一些东西无济于事。

app.controller('ViewOneArtist', function($scope, $http, $resource, artistesUrl, baseUrl, $stateParams) {

$scope.artistesItemsResource = $resource(baseUrl + artistesUrl + $stateParams.id, {id: "@id"},
    { create : { method: "POST"}, save: { method: "PUT"}}
);

$scope.id = $stateParams.id;

console.log($scope.id);

console.log("got to here...before listOneArtiste");

$scope.listOneArtiste = function(id) {
    $scope.artistesItem = $scope.artistesItemsResource.get(id);
};

console.log("got to here...after declared listOneArtiste");

$scope.listOneArtiste($stateParams.id);

console.log("got to here...after calling listOneArtiste");

});

Console.log 从 $scope.id 或 $stateParams.id 返回一个值(例如:43),但是当我调用函数 listOneArtist() 时,它会抛出上述错误。有什么建议吗?

【问题讨论】:

    标签: javascript angularjs safari


    【解决方案1】:

    在测试了几个项目之后,我自己修复了它,这是解决方案:

    app.controller('ViewOneArtist', function($scope, $http, $resource, artistesUrl, baseUrl, $stateParams) {
    
    $scope.artistesItemsResource = $resource(baseUrl + artistesUrl + $stateParams.id, {id: "@id"},
        { create : { method: "POST"}, save: { method: "PUT"}}
    );
    
    $scope.id = {id: $stateParams.id};
    
    $scope.listOneArtiste = function(id) {
    
        id = this;
    
        $scope.artistesItem = $scope.artistesItemsResource.get(id);
    };
    
    
    $scope.listOneArtiste($scope.id);
    
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-14
      • 1970-01-01
      • 1970-01-01
      • 2021-01-03
      • 2018-05-30
      • 1970-01-01
      相关资源
      最近更新 更多