Aid*_*Gee 13 twitter angularjs angularjs-directive ng-view
嗨,谢谢你的阅读.
我有一个角色应用程序正在制作和我偶然发现了一个问题.如此设置
index.html-
<html ng-app="myApp">
...
<div ng-view></div>
<div ng-include="'footer.html'"></div>
...
</html>
Run Code Online (Sandbox Code Playgroud)
我不会打扰我的路线很简单/家是显示/home/index.html等等...
/home/index.html(当你来到网站时的默认视图)
<div class="responsive-block1">
<div class="tweet-me">
<h1> tweet me </h1>
</div>
<div class="twitter-box">
<twitter-timeline></twitter-timeline>
</div>
Run Code Online (Sandbox Code Playgroud)
twitter时间线指令
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();
}
};
});
Run Code Online (Sandbox Code Playgroud)
所以我刚刚使用twitter上的标签创建了一个基本的twitter指令.但是当我将视图示例更改为/ blog然后返回/ home时,twitter小部件根本不再呈现.
我也使用$ anchorScroll,如果我在页面上跳转到这个小部件也会消失.任何信息都会非常感谢.
Car*_*arl 10
请看这篇文章:https://dev.twitter.com/discussions/890
我认为您可以通过调用twttr.widgets.load()来重新呈现窗口小部件.
如果您发现这不起作用,则需要在控制器中将此代码包装到$ timeout中:
controller('MyCtrl1', ['$scope', '$timeout', function ($scope, $timeout) {
$timeout = twttr.widgets.load();
}])
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5874 次 |
| 最近记录: |