0
我想在ng-repeat中调用异步函数。我相信,这是不是这样做的正确的方式,但想知道什么是正确的“角办法”在ng-repeat中调用异步函数
<tr ng-repeat="app in multipleApps">
<td><h4> {{ app.Name }} </h4></td>
<td><h4> {{ getActivationDate(app.Name) }} </h4></td>
</tr>
在控制器getActivationDate调用工厂函数返回一个承诺。所以我需要知道如何在ng-repeat中使用这个函数。
$scope.getActivationDate = function(name)
{
Service.getActivationDate(appName)
.then(function(response) {
var ts = response.activated_at;
var date = new Date(ts *1000);
console.log(date.toDateString());
return date.toDateString();
},
function(error)
{
$scope.error = true;
});
}
Service.getMultipleApps()
.then(function(data) {
$scope.$apply(function() {
$scope.multipleApps = data;
});
});
感谢
App对象不具有 'activationDate' 字段,所以我不能像这样指定 – tech74
@ tech74它会创建新的字段,您可以访问它 - 它会可用时打印。 – hsz
感谢它的运作良好 – tech74