我正在使用 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/