ionic-team / ionic-v1

The repo for Ionic 1.x. For the latest version of Ionic, please see https://github.com/ionic-team/ionic
Other
193 stars 187 forks source link

Filter aliasing doesn't work with collection-repeat #152

Open jgw96 opened 7 years ago

jgw96 commented 7 years ago

From @mnewmedia on March 29, 2016 11:9

Short description of the problem:

Filter aliasing doesn't work with collection-repeat.

What behavior are you expecting?

That it works, like when using ng-repeat ;)

Steps to reproduce:

  1. Create a collection repeat list
  2. Add a filter
  3. as soon as you try to add an alias as filteredCollection it breaks
collection-repeat="customer in customers | filter:myFilter as filteredCollection"

Other information: Somebody hacked the collection-repeat to make it work, but would be nicer if it could be official supported by ionic, so we don't lose the hacked feature when updating the ionic see forum post.

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

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

// 3. make the alias available in the scope right under "collection-repeat expected an array for"
if (aliasExpr) {
  scope[aliasExpr] = newValue;
}

Which Ionic Version? 1.x or 2.x 1.x latest

Run ionic info from terminal/cmd prompt: (paste output below) Cordova CLI: 6.0.0 Ionic Version: 1.2.4 Ionic CLI Version: 2.0.0-beta.17 Ionic App Lib Version: 2.0.0-beta.8 ios-deploy version: 1.8.5 ios-sim version: 5.0.6 OS: Mac OS X El Capitan Node Version: v5.3.0 Xcode version: Xcode 7.3 Build version 7D175

Copied from original issue: driftyco/ionic#5979