datatype_void datatype_void - 10 months ago 47
Javascript Question

ng-if not catching updated $scope values

I have been away from

angular 1.x
for so long I seem to have forgotten something important about
. I have a function which updates a scope value whenever a carousel changes images which is tracking the active index of the carousel array. I have
set to remove one element and insert another when the index reaches the end of the array, something like this:

<span ng-if="activeIndex < 4"
ui-sref="app.profile.index({uID: user.uID})">
Skip <i class="ion-chevron-right"></i>

<span ng-if="activeIndex === 4"
ui-sref="app.profile.index({uID: user.uID})">
Continue <i class="ion-chevron-right"></i>

but it isn't working. I believe that
creates a new scope so that may be why it isn't catching the updated values, but if that is the case, what is an easy way to update the scope of
? Or am I completely turned around?

Here's a
showing my problem:


I added a $scope.$apply(); after the activeIndex change, and that solved the problem.

  $scope.activeIndex = swiper.activeIndex;

though I'm not sure why it isn't applied automatically.

Working code:

(also changed the max value to 2 because it never got to 4 before, but that wasn't the problem.)