I'm facing an issue with my controller where the Gui $scope
is not updating properly. After conducting some research, I discovered that using $timeout
could potentially help.
The service's processing time varies on different units and setting a fixed 5000 timeout seems to slow down the app. Are there any alternative methods to accomplish this?
.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) {
// Non-functional example
$scope.rows = data;
// Functional example
$timeout(function () {
$scope.rows = data;
}, 5000)
}