I'm working on setting an interval in my app and I have the following code:
HTML
<div class="text">
{{currentItem.name}}
</div>
<ul>
<li ng-repeat="item in items" ng-click="pickItem($index)">{{item.type}}</li>
</ul>
Controller
$scope.index = 0;
$scope.currentItem = $scope.items[$scope.index]; // set the first item
// The interval starts 3 seconds after the app is loaded
$scope.startInt = $interval(function() {
$scope.currentItem = $scope.items[$scope.index];
$scope.index++;
if(scope.index === $scope.items.length) {
$scope.index=0;
}
}, 3000)
The above code will start the interval 'AFTER' the page is loaded for 3 seconds. Is there any way to initiate the interval immediately when the page first loads? Thank you!