为什么如果我改变angularjs认为我的Twitter部件无法呈现? [英] Why will my twitter widget not render if i change the view in angularjs?
问题描述
Hi和感谢您的阅读。
Hi and thanks for reading.
我有一个角应用IM决策和香港专业教育学院无意中发现了一个问题。设置如此
I have a angular app im making and ive stumbled on a problem. set up as so
index.html的 -
index.html-
<html ng-app="myApp">
...
<div ng-view></div>
<div ng-include="'footer.html'"></div>
...
</html>
我不会打扰把我的路线及其pretty简单/家显示/home/index.html等等...
I wont bother putting my routes its pretty simple /home is shows the /home/index.html and so on...
/home/index.html(当你来到现场默认视图)
/home/index.html (default view when you come to the site)
<div class="responsive-block1">
<div class="tweet-me">
<h1> tweet me </h1>
</div>
<div class="twitter-box">
<twitter-timeline></twitter-timeline>
</div>
Twitter的时间表指令
twitter timeline directive
directives.directive("twitterTimeline", function() {
return {
restrict: 'E',
template: '<a class="twitter-timeline" href="https://twitter.com/NAME" data-widget-id="XXXXXXXXXXXXXX">Tweets by @NAME</a>',
link: function(scope, element, attrs) {
function run(){
(!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"));
console.log('run script');
};
run();
}
};
});
所以我刚刚创建使用从Twitter标签一个基本的Twitter指令。但是,当我改变观点例子/博客然后返回到/ home twitter的小部件不再呈现在所有。
So I have just created a basic twitter directive using the tag from twitter. But when I change the view example to /blog then go back to /home the twitter widget no longer renders at all.
林也使用$ anchorScroll,如果我反正跳转到页面上的这个小部件也消失了。任何信息将是巨大的,谢谢。
Im also using an $anchorScroll and if i jump to anyway on the page with this the widget also disappears. Any info would be great thanks.
推荐答案
请参阅这篇文章: https://dev.twitter.com /讨论/ 890
我觉得你可能是能够获得小部件通过调用重新呈现
twttr.widgets.load()。
I think that you may be able to get the widget to re-render by calling twttr.widgets.load().
如果你发现这不起作用,则需要这裹code到$超时在你的控制器:
If you find that this does not work, you will need to wrap this code into $timeout in your controller:
controller('MyCtrl1', ['$scope', '$timeout', function ($scope, $timeout) {
$timeout = twttr.widgets.load();
}])
这篇关于为什么如果我改变angularjs认为我的Twitter部件无法呈现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!