Indexed list and collection-repeat

Ok. Had to hack my way through.

Step 1. Add alias to ionic’s collection repeat. Go to ionic.bundle.js on the CollectionRepeatDirective and add this to the regex.

var match = repeatExpr.match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);

After this, add:

var aliasAs = match[3]; // AC: Added this
// Alias test
if (aliasAs && (!/^[$a-zA-Z_][$a-zA-Z0-9_]*$/.test(aliasAs) ||        /^(null|undefined|this|\$index|\$first|\$middle|\$last|\$even|\$odd|\$parent|\$root|\$id)$/.test(aliasAs))) {
  throw Error("alias " + aliasAs +" is invalid --- must be a valid JS identifier which is not a reserved name.");
}

And below on the scope.$watchCollection call, add the following before the timeout function:

scope.$watchCollection(listGetter, function(newValue) {
  newValue || (newValue = []);

  if (!angular.isArray(newValue)) {
    throw new Error("collection-repeat expected an array for '" + listExpr + "', " +
      "but got a " + typeof value);
  }

  // AC: Adding alias as from angular.js' ng-repeat
  if (aliasAs) {
    scope[aliasAs] = newValue;
  }

  // Wait for this digest to end before refreshing everything.
  $timeout(function() {
    getRepeatManager().refreshData(newValue);
    if (newValue.length) refreshDimensions();
  }, 0, false);
});

Step 2. On the scroll function on your controller, add the following:

$scope.scrollTo = function(recipeeId) {
  // The following code works with ng-repeat but not with collection-repeat
  //$location.hash(location);
  //$ionicScrollDelegate.anchorScroll();
  
  // collection-repeat workaround
  var items = $scope.$$childHead.filteredItems;
  var scrollHeight = 0;
  for (var i = 0; i < items.length; i++) {
    if (items[i].id == recipeeId) {
      $ionicScrollDelegate.scrollTo(0, scrollHeight, true);
    }
    scrollHeight += $scope.getItemHeight(items[i], i);
  }
};

Still not the best way to do it, and I have to reference the $$childHead which is suboptimal. If any of you Ionic devs have any comments or possible inclusions to collection-repeat, please let me know.