Javascript ng重复不随对象增长
我正在这样做:Javascript ng重复不随对象增长,javascript,angularjs,Javascript,Angularjs,我正在这样做: <body> <div ng-controller="PresentationCtrl"> <a href="" ng-click="findAll()">Find</a> <div> <ul class ="unstyled"> <li ng-repeat="p in presentations">
<body>
<div ng-controller="PresentationCtrl">
<a href="" ng-click="findAll()">Find</a>
<div>
<ul class ="unstyled">
<li ng-repeat="p in presentations">
<img ng-src="{{p}}" alt="presentation">
</li>
</ul>
<div>
</div>
</body>
它很好用
你的情况可能不同
---------编辑---------
好的,我了解你的情况。您正在运行一个不受AngularJS监视的函数。
因此,AngularJS不知道您的变量已更改,基本上不调用$digest
为了模拟本机Javascript异步调用,我使用setTimeout
以下代码不起作用。它会更改值,但不会被监视
setTimeout( function() {
$scope.presentations = [6,7,8,9];
}, 1000);
但是,此代码不起作用。它会按预期更改值
$timeout( function() {
$scope.presentations = [6,7,8,9];
}, 1000);
setTimeout和$timeout之间的区别在于$timeout是在AngularJS的监视下运行的。
因此,要使其工作,您需要在其之后或作为函数在其内部运行$scope.apply()
此代码与setTimeout
一起工作
setTimeout( function() {
$scope.presentations = [6,7,8,9];
$scope.$apply();
}, 1000);
无法向您详细解释所有内容,因为我没有真正掌握AngularJS代码
这个博客很好地解释了为什么我们需要运行$apply
为了快速得到答案,最好在JSFIDLE或plunkr中有一个简化的示例。我知道$http调用不能在plunkr或JSFIDLE中演示,但您可以使用
setTimeout
模拟您的情况。大多数时候,它可以让读者理解您的情况。我们可以看到您的演示文稿trl
控制器吗?我们确实需要控制器来帮助。您确定在console中看到了吗?“从signedUrls返回”…?我遇到了与datatables.net xhr.dt事件相同的问题,该事件没有刷新网格。
setTimeout( function() {
$scope.presentations = [6,7,8,9];
$scope.$apply();
}, 1000);