twitter-widget

By: Ryan Wong at

Here’s how you create a twitter widget.

Controller:

1
TwitterService.load();

Directive:

1
2
3
4
5
6
7
8
9
angular('app').factory('TwitterService', ['$timeout', function ($timeout) {
return {
load: function () {
$timeout(function() {
$.ajax({ url: 'http://platform.twitter.com/widgets.js', dataType: 'script', cache:true});
}, 1000);
}
}
}]);

HTML:

1
2
<a class="twitter-timeline" href="https://twitter.com/company" data-widget-id="411817353240772608">Tweets by @company</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+"://platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>