Angular: transclude example 1.3
http://angularjs.org/
by Michael Freake
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.js"></script>
<div ng-controller="FeedController">
<div class="row">
<div class="col-md-4">
<h1>News Feed 1</h1>
<ul>
<li ng-repeat="feed in rotoWorld" class="">
<h5><a href="{{feed.link}}">{{feed.title}}</a></h5>
<p>{{feed.content}}</p> <small>Date: {{feed.publishedDate}}</small>
<small ng-show="feed.author" class="">Author: {{feed.author}}</small>
</li>
</ul>
<p><a href="#" role="button" ng-click="loadFeeds();">Refresh this feed »</a>
</p>
</div>
</div>
</div>
JavaScript
(function () {
var app = angular.module('newsFeed', []);
app.controller('FeedController', ['$scope', 'FeedService', function ($scope, Feed) {
console.log('FeedController called.');
//These calls cause errors:
//$scope.loadFeeds();
//loadFeeds();
//this.loadFeeds();
//loadFeeds();
$scope.loadFeeds = function () {
console.log('loadFeeds called.');
Feed.parseFeed('http://www.rotoworld.com/rss/feed.aspx?sport=nfl&ftype=article&count=12&format=atom').then(function (res) {
$scope.rotoWorld = res.data.responseData.feed.entries;
});
};
}]);
app.factory('FeedService', ['$http', function ($http) {
return {
parseFeed: function (url) {
return $http.jsonp('http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&num=50&callback=JSON_CALLBACK&q=' + encodeURIComponent(url));
}
};
}]);
})();