簡體   English   中英

如何解決錯誤獲取Feed:角度未定義?

[英]how to fix error fetching feed: undefined in angular?

我在Chrome瀏覽器中收到一條錯誤消息,提示錯誤:提取Feed:未定義,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);
};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM