gpt4 book ai didi

angularjs - 如果我在 angularjs 中更改 View ,为什么我的 twitter 小部件不会呈现?

转载 作者:行者123 更新时间:2023-12-03 23:29:56 25 4
gpt4 key购买 nike

您好,感谢您的阅读。

我正在制作一个有 Angular 的应用程序,我偶然发现了一个问题。如此设置

index.html-

<html ng-app="myApp">
...
<div ng-view></div>
<div ng-include="'footer.html'"></div>
...
</html>

我不会费心把我的路线它非常简单的/home 是显示/home/index.html 等等......

/home/index.html(访问站点时的默认 View )
<div class="responsive-block1">
<div class="tweet-me">
<h1> tweet me </h1>
</div>

<div class="twitter-box">
<twitter-timeline></twitter-timeline>
</div>

推特时间线指令
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 指令。但是当我将 View 示例更改为/blog 然后返回/home 时,twitter 小部件根本不再呈现。

我也在使用 $anchorScroll ,如果我用这个跳转到页面上的任何地方,小部件也会消失。任何信息都会非常感谢。

最佳答案

看到这个帖子:https://dev.twitter.com/discussions/890

我认为您可以通过调用来重新渲染小部件
twttr.widgets.load()。

如果您发现这不起作用,则需要将此代码包装到 Controller 中的 $timeout 中:

    controller('MyCtrl1', ['$scope', '$timeout', function ($scope, $timeout) {
$timeout = twttr.widgets.load();
}])

关于angularjs - 如果我在 angularjs 中更改 View ,为什么我的 twitter 小部件不会呈现?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22231350/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com