Questions tagged [angularjs-timeout]

$timeout is Angular's wrapper for window.setTimeout.

$timeout is Angular's wrapper for window.setTimeout. The fn function is wrapped into a try/catch block and delegates any exceptions to $exceptionHandler service.

The return value of registering a timeout function is a promise, which will be resolved when the timeout is reached and the timeout function is executed.

Source

23 questions
182
votes
2 answers

What's the difference between $evalAsync and $timeout in AngularJS?

I've been using AngularJS for a little while now, and have found the need to use $timeout every once in a while (Seems to usually be to init a jQuery plugin). Recently, I've been trying to get a better and more in-depth understanding of the digest…
dnc253
  • 39,967
  • 41
  • 141
  • 157
9
votes
3 answers

How do I use $timeout service in a Directive?

Basically, I want to measure the width of the element after angular has manipulated the DOM. So I would like to use $timeout for that, but it keeps getting me errors. HTML
9
votes
1 answer

What's the right way to wait for ng-init values to be set?

I have an "ng-init" directive in my HTML that initializes the value of "data.id" in my Angular.js data model. Let's say for now that I can't change how this works. Now, I want to make an HTTP request as soon as my page loads, where the URL will…
Eugene Osovetsky
  • 6,443
  • 2
  • 38
  • 59
4
votes
2 answers

Simulate the passage of time in protractor?

I have a few spots where things happen in the UI on a delay using $timeout or $interval. Here's a simplified example: Controller code: $timeout(function() { $scope.showElement = true; }, 10000); HTML:
peteallen
  • 2,553
  • 2
  • 17
  • 16
3
votes
3 answers

How can clear $timeout in angularjs

I have this code for image slider and next prev and auto change the image function scope.next = function () { scope.currentIndex < scope.images.length - 1 ? scope.currentIndex++ : scope.currentIndex = 0; }; scope.prev = function () { …
3
votes
2 answers

Is any event "on $scope digest finished" or "on view refreshed" in Angular.js?

I'm doing an AJAX request for data that is used in the view for generation of a list. I need to know when the $scope is updated and when the view is rendered after a successful response received, so that I can set dynamically some initial values and…
Galya
  • 6,294
  • 6
  • 27
  • 45
3
votes
1 answer

AngularJS $timeout sometimes works sometimes doesn't

I'm experiencing some problems with AngularJS and $timeout. I need to run some code, after the page is loaded. Http.get() loads items and ng-repeat displays them in table. Then I need to run the code to highlight row when I click it. I found a…
2
votes
4 answers

Trigger ng-show after delay

I want to make a div appear 10s after the page has loaded. I would like to use angular.
Any ideas how i might accomplish this? Is there any way to trigger, say a function after a set time? I…
andrea
  • 103
  • 3
  • 14
2
votes
1 answer

AngularJS: avoid using $timeout to wait for image loading completion

I'm trying to create my own image carousel as an angularjs directive; I want to keep it as lightweight and unopinionated as possibile, so I thought I'd just create a wrapper for a set of elements, like so:
2
votes
1 answer

AngularJS: Why and when calling $timeout is required?

Live Demo I created a confirmationDialogHeader directive which is used like so:
2
votes
1 answer

angularjs save changes after digest has finished

I think this might be quite common use-case with any angular app. I am simply watching some objects on my scope that are changed as part of several digest cycles. After digesting them (changing their values via databinding) has finished, I want to…
honzajde
  • 2,270
  • 3
  • 31
  • 36
1
vote
1 answer

In an Angular.js controller's scope function code doesn't run below a $timeout statement inside

I have a button for which I have set ng-click="refresh()". The console logs before the timeout function logs correctly but the console log inside the $timeout block and after the block doesn't seem to log. If I remove the $timeout block every…
1
vote
2 answers

Can we update $timeout in AngularJS?

Following is what I'm trying to do. When the first timeout is forcibly cancelled, I want to initiate the second timeout function, without the lag that already exists, had the timeout not been cancelled. $scope.data1_timeout = $timeout(function()…
Siena
  • 778
  • 10
  • 23
1
vote
1 answer

AngularJS: Injecting $timeout not available in directive

I am injecting $timeout into the following directive but it is not defined. The following code prints undefined to the console and throws TypeError: $timeout is not a function; export default class foo { constructor ($timeout) { …
1
vote
1 answer

Cancel a resource request in angular

I am new to angular so I need detailed solution to this question. I have seen a lot of answers but not according to my situation. I have a service: function ticketService($resource, globals) { return $resource(globals.API_URL+'/tickets/:id',…
1
2