I found questions similar to this , but most of them ended up being about ng-repeat or something similar, which is not what I am after here.
In my case I am trying to loop through an array of messages to display one message at a time in the view. Here is my view:
<div id="centerWrap" ng-init="looptyloop()">
<p>{{centerWrapMessage[loop.loop]}}</p>
</div>
My controller has both $scope.centerWrapMessage and $scope.loop.
My controller is here:
$scope.centerWrapMessage = ["Click your category and then click your bread for more information.","If you intend to ship your order, please select a gift box","To add an item to your cart, hit the cart button"],
$scope.loop = {
loop: 0
},
$scope.looptyloop = function() {
var i = 0;
function myLoop () {
setTimeout(function () {
i++;
$scope.loop.loop = i;
if (i == $scope.centerWrapMessage.length - 1){
i = -1;
}
if (i < $scope.centerWrapMessage.length) {
myLoop();
}
}, 2222)
}
myLoop();
},
I can see in the console log (when I put it in) that the $scope.loop.loop is looping through like I want, but it never changes in the view. Why is this?
Thank you!