Fix bug by adding `scope.$apply` to the assignment of `scope.index`.