2014-01-14 189 views
3

我試圖按照此tutorial瞭解如何創建閱讀器,但似乎無法正常工作。具體來說,$http.jsonp(...)調用似乎不起作用。它掛起約20秒,然後簡單地返回一個GET錯誤。AngularJS RSS提要閱讀器

這是完整的Angular代碼。

var app = angular.module('RSSFeedApp', []); 

app.controller("FeedCtrl", ['$scope','FeedService', function ($scope,Feed) {  
    $scope.loadButonText="Load"; 
    $scope.feedSrc="http://sports.espn.go.com/espn/rss/news"; 

    $scope.loadFeed=function(e){   
     Feed.parseFeed($scope.feedSrc).then(function(res){ 
      $scope.loadButonText=angular.element(e.target).text(); 
      $scope.feeds=res.data.responseData.feed.entries; 
     }); 
    } 
}]); 

app.factory('FeedService', ['$http', function($http){ 
    return { 
     parseFeed : function(url) { 
      return $http.jsonp('//ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=50&callback=JSON_CALLBACK&q='+ encodeURIComponent(url)); 
     } 
    } 
}]) 

是否有不同的/更好的方式來做角度的RSS訂閱源,或者我只是錯過了明顯的東西?

回答

0

想通了。

我的應用程序還沒有託管在任何外部服務器上,它現在只是在我的機器上運行,而我通過瀏覽器訪問文件位置。

例如:

file:///C:/Users/... 

jQuery的調用//ajax.googleapis...然後傳送到文件位置,而不是Web地址。將//ajax.googleapis...更改爲https://ajax.googleapis...解決了此問題。

簡單的錯誤,但容易忽略我想。

-1

我編寫了一個模塊,並提供了一個將Google Feed API集成到AngularJS應用程序中的示例。您可以查看文章here