コントローラに問題があり、Gui $scope
が更新されません。 調査の結果、$timeout
を使用できることが判明しました。
サービスが異なるユニットで異なる時間がかかるため、アプリケーションの速度が遅いために5000タイムアウトに設定したくありません。 これを行うための他の方法はありますか?
.service('RowService', function ($q) {
var rows = undefined;
this.getrows = function (id) {
var local = new PouchDB('db');
var deferred = $q.defer();
// var rows = [];
local.query(function (doc, emit) {
emit(doc.type);
}, { key: 'row_detail' }).then(function (result) {
var rows = [];
for (i = 0; i < result.rows.length; i++) {
local.get(result.rows[i].id).then(function (response) {
if (response.orderid == orderId) {
rows.push(response);
}
deferred.resolve(rows);
})
}
}).catch(function (err) {
// handle any errors
});
rows = deferred.promise;
return $q.when(rows);
}
})
RowService.getrows($stateParams.id).then(function (data) {
// Not working example
$scope.rows = data;
// Working example
$timeout(function() {
$scope.rows = data;
}, 5000)
}
'$ timeout'関数は、タイムアウトの終わりに' $ scope。$ apply() 'を呼び出します。したがって、' $ scope.rows 'を指定した後に '$ scope。$ apply()'を呼び出すことができます。 =データ '? –
なぜあなたはdeferred.resolve(rows)を持っていますか?あなたのforループの中に? –