5

I get this error https://code.angularjs.org/1.3.16/docs/error/ngRepeat/badident when I try to use ngRepeat alias as syntax with controller as syntax:

<li ng-repeat="item in vm.items | filter:vm.searchString as vm.collections">{{item}}</li>

It's not allowed or I do something wrong?

Ivan G
  • 404
  • 1
  • 4
  • 17

3 Answers3

9

if you need to store the result on the vm variable you can do it like this

<li ng-repeat="item in vm.collections = (vm.items | filter:vm.searchString)">{{item}}</li>

If not then Donal's solution will work

rob
  • 17,995
  • 12
  • 69
  • 94
  • 1
    Thank you rob.Indeed this is what I was and still doing in my code. But I saw the alias as approach in ngRepeat docs and was wondering if it's working with dot syntax variables. I guess it's not possible yet. – Ivan G Jun 09 '15 at 06:32
  • 1
    If you are using 'track by', make sure to close the parenthesis before track by. e.g. (vm.items | filter:vm.searchString) track by item.id – Mehdi Karamnejad May 03 '17 at 19:37
1

Should be a simple identifier (such that you could declare it with var {name})

<li ng-repeat="item in vm.items | filter:searchString as collections">{{item}}</li>
Donal
  • 31,121
  • 10
  • 63
  • 72
0

I figured out why I was getting a similar issue.

Angular documentation isn't explicit about this... But if you're going to use Controller As syntax, you MUST set your model values to "this" on your controller. You CANNOT set the values to $scope.

When you inspect the $scope after you alias, you can see a new property on your parent $scope with the name of your alias.

My alias was pmt. I changed my properties and functions from

$scope.myProperty  

to

var vm = this;
vm.myProperty

When you inspect the $scope.$parent of my aliased controller, you see vm listed on it's properties. That's how they do aliasing.

Really wish the documentation was explicit on this.

Fred
  • 1,344
  • 1
  • 11
  • 16