javascript - Angular 变量更新,但不刷新其周围的推文嵌入代码

标签 javascript angularjs

我正在使用 Angular 循环遍历数组中的一堆推文 ID,并将它们呈现到由 Twitter 嵌入代码包围的页面。问题是变量正在更新,但 Twitter 嵌入没有被刷新。它看起来像这样:

HTML:

<!--output the variable for testing (works fine)-->

{{tweets[index].twitterID}} 


<!--twitter embed code wrapped around the above variable -->

<blockquote class="twitter-tweet" width="500" align="center" lang="en">
    <a ng-href="https://twitter.com/user/statuses/{{tweets[index].twitterID}}"></a>
    <script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
</blockquote>


<!--button to cycle to next tweet-->

<div id="btn" ng-click="increment()">Next</div>

脚本:

$scope.tweets = [] //my tweets json object

$scope.index = 0;
$scope.increment = function () {
     $scope.index = $scope.index + 1;
 }

第一条推文嵌入得很好,虽然下一个按钮确实更新了变量,但推文嵌入没有改变。有谁知道为什么吗?

最佳答案

我在索引更改上放置了 $watch 语句,并使用新变量渲染了整个 twitter 嵌入代码。看来问题已经解决了。

关于javascript - Angular 变量更新,但不刷新其周围的推文嵌入代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22202291/

相关文章:

javascript - FCSA 编号指令在最新版本的 Angular 中不起作用

javascript - 传单上的 Bootstrap 行

Javascript:运行在此闭包外部定义的函数,就像在该闭包内部定义的一样

javascript - Jasmine 无法实例化 Angular 模块?

javascript - 如何检查值(value)服务是否已经定义angularjs

javascript - 使用 javascripting DOM 脚本隐藏 div,具体取决于单选按钮的总和

javascript - 为什么 Number#toLocaleString() 在 webkit 控制台和节点控制台中都不能按预期工作?

javascript - AngularJS ng-options 错误 : Can't copy! 不支持制作 Window 或 Scope 实例的副本

javascript - ng-src 发生变化,photo.src 变化有一些延迟

javascript - AngularJS 不编译具有 ng-repeat 的元素