如何修复错误获取饲料:角度未定义

how to fix error fetching feed: undefined in angular?

本文关键字:未定义 何修复 错误 获取      更新时间:2023-09-26

我在Chrome中收到一个错误,说错误获取提要:未定义,0。有什么建议吗?

我的角度代码是:

        // Begin SimpleController, with data
        demoApp.controller('SimpleController', function($scope, $http){
            var url = "http://www.grabapper.com/api/v1/iosapps.json";
            $http.jsonp(url).
                success(function(data,status,headers,config){
                    $scope.feed = {
                        title: 'DailyJS',
                        items: data
                    };
                }).
                error (function(data,status,headers,config){
                    console.error('Error fetching feed:', data,status);
                });
        });
        // End SimpleController

all.html:

<li ng-repeat="item in feed.items">
            {{item.name}}
    </li>

因为您正在客户端代码中调用跨域API。您可以签出此解决方案。

以下是可能对有所了解的代码片段

$http.defaults.useXDomain = true;
var data =$resource(url);
if(data){
    $scope.feed = {
        title: 'DailyJS',
        items: data
    };
}else{
    console.error('Error fetching feed:', data);
};