pbastowski / angular2-now

Angular 2 @Component syntax for Angular 1 apps
MIT License
145 stars 15 forks source link

Error when using $regex in subscription #24

Closed vacarsu closed 9 years ago

vacarsu commented 9 years ago

I get the following when trying to use $regex in a subscription.

SyntaxError: Invalid regular expression: /*/: Nothing to repeat
    at RegExp (native)
    at new RegExp (http://localhost:3000/packages/pbastowski_angular-babel.js?12301086a7dabca46b24c7091e4fcb4205034f68:1942:14)
    at Object.ELEMENT_OPERATORS.$regex.compileElementSelector (http://localhost:3000/packages/minimongo.js?cdf1a26cf7719fa9471a8017c3defd5aea812727:1904:18)
    at http://localhost:3000/packages/minimongo.js?cdf1a26cf7719fa9471a8017c3defd5aea812727:1509:19
    at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?46eaedbdeb6e71c82af1b16f51c7da4127d6f285:157:22)
    at operatorBranchedMatcher (http://localhost:3000/packages/minimongo.js?cdf1a26cf7719fa9471a8017c3defd5aea812727:1489:5)
    at compileValueSelector (http://localhost:3000/packages/minimongo.js?cdf1a26cf7719fa9471a8017c3defd5aea812727:1393:12)
    at http://localhost:3000/packages/minimongo.js?cdf1a26cf7719fa9471a8017c3defd5aea812727:1372:9
    at Function._.each._.forEach (http://localhost:3000/packages/underscore.js?46eaedbdeb6e71c82af1b16f51c7da4127d6f285:157:22)
    at compileDocumentSelector (http://localhost:3000/packages/minimongo.js?cdf1a26cf7719fa9471a8017c3defd5aea812727:1355:5)

Here is the the subscription.

this.result = $scope.$meteorCollection(() => {
  return Collection.find({
    $or: [
      { title: {$regex:$scope.getReactively('vm.value')+'*'} },
      { tags: {$regex:$scope.getReactively('vm.value')+'*'} }
    ]
  })
}, false).subscribe('search-publication', $scope.getReactively('vm.value'));
pbastowski commented 9 years ago

Doesn't look much like it's related to angular2-now. However, let's see if I can help you anyway...

At first looks I think your $scope.getReactively('vm.value') is returning either an undefined or an empty string. If that's the case then the error message makes sense, because you can't do a /*/ regex. There must be something before the *. So, /a*/ would match any number of "a"s, for example.

But, if the above doesn't point you in the right direction, then please include the below with further questions:

vacarsu commented 9 years ago

I worked around it by using using an autorun function and only running the subscription if vm.value isn't null or undefined.