简体   繁体   中英

Using the Angular interval timer function

I have a created a basic image slider which works well.

I am trying to make attempts to add the angular $interval service to my function in order for the slide to transition automatically.

Does any know how this can be achieved I am assuming this function only requires one or two lines of code. I've also Plunkr

// JOBS FLICKR FUNCTIONS 

$scope.jobNotification = 0;

var timer = $interval();

$scope.isActive = function (index) {
    return $scope.jobNotification === index;
};

$scope.showJobNotification = function (index) {
    $scope.jobNotification = index;
};

I've quite a few versions in bootstrap, however i trying to build something manually so i can understand what i am doing.

$interval takes in a function which will be called every X seconds.

var timeBetweenEachInterval = 5 * 1000; //5 seconds (or 5000 milliseconds)
var intervalPromise = $interval(function () { 
  //This function will be called every 5 seconds.
  index = index + 1;
  if (/*don't need interval anymore*/) {
    $interval.cancel(intervalPromise);
  }
}, timeBetweenEachInterval);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM