I'm trying to figure out how to implement a promise into a function in order to eliminate the use of a timeout. Is this even possible? The function I have is pulling data from a factory called 'Prim' and it looks like this:
$scope.getPre = function(id){
var url = WEB_API.MainUrl + '/api/prim/' + id +'/' + $window.sessionStorage.getItem('idsom');
Prim.getprim(function(data) {
$scope.prim1 = data;
$scope.prim = $scope.prim1[0];
}, url);
$scope.$apply();
}
Currently, I am using a timeout that I want to remove:
setTimeout(function() { // the function doesn't work without timeout
$scope.getPre($routeParams.idprim);
}, 100);