让这个脚本读取一些RSS源。单击链接
时,它工作正常<a href="#" ng-click="feedSrc='http://feeds.feedburner.com/TechCrunch';loadFeed($event);">TechCrunch</a>
但我希望在页面加载时直接加载第一个Feed的结果
感谢一些帮助。 Example here
HTML:
<div data-ng-controller="FeedCtrl" ng-app="RSSFeedApp">
<p>
<a href="#" ng-click="feedSrc='http://feeds.feedburner.com/TechCrunch';loadFeed($event);">TechCrunch</a> |
<a href="#" ng-click="feedSrc='http://rss.cnn.com/rss/cnn_topstories.rss';loadFeed($event);">CNN</a>
</p>
<ul class="unstyled">
<li ng-repeat="feed in feeds | filter:filterText">
<h5><a href="{{feed.link}}">{{feed.title}}</a></h5>
<p class="date">{{feed.publishedDate | date : format : timezone}}</p>
</li>
</ul>
</div>
JS:
var App = angular.module('RSSFeedApp', []);
App.controller("FeedCtrl", ['$scope', 'FeedService', function($scope, Feed) {
$scope.loadFeed = function(e) {
Feed.parseFeed($scope.feedSrc).then(function(res) {
$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=5&callback=JSON_CALLBACK&q=' + encodeURIComponent(url));
}
}
}]);
答案 0 :(得分:1)
很高兴找到你的代码,所以我决定还你的回报:
<div data-ng-controller="FeedCtrl" ng-app="RSSFeedApp" ng-init="feedSrc='http://feeds.feedburner.com/TechCrunch';loadFeed($event);">
<p>
<a href="#" ng-click="feedSrc='http://feeds.feedburner.com/TechCrunch';loadFeed($event);">TechCrunch</a> |
<a href="#" ng-click="feedSrc='http://rss.cnn.com/rss/cnn_topstories.rss';loadFeed($event);">CNN</a>
</p>
<ul class="unstyled">
<li ng-repeat="feed in feeds | filter:filterText">
<h5><a href="{{feed.link}}">{{feed.title}}</a></h5>
<p class="date">{{feed.publishedDate | date : format : timezone}}</p>
</li>
</ul>
</div>