I would like to change in my script the ng-repeat to something else (for example foo to foo2) when i do something (clicking on a button for example). Is it possible ?
Short Answer
No
AngularJS parses ng-repeat directive value and expects pattern item in collection
But you can replace list through which you iterate.
<div id="test" ng-repeat="item in foo()">
where foo() might be some method that returns array of objects
But is it possible to change the function foo() with foo2() dynamically ?
you can write method foo() as:
$scope.foo = function(){
if($scope.clicked){
return array1;
}
alse{
return array2;
}
}
Details
From Angular_6.6
var expression = $attr.ngRepeat;
var ngRepeatEndComment = $compile.$$createComment('end ngRepeat', expression);
var match = expression.match(/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+track\s+by\s+([\s\S]+?))?\s*$/);
if (!match) {
throw ngRepeatMinErr('iexp', 'Expected expression in form of \'_item_ in _collection_[ track by _id_]\' but got \'{0}\'.',
expression);
}
The pattern is:
/^\s*([\s\S]+?)\s+in\s+([\s\S]+?)(?:\s+as\s+([\s\S]+?))?(?:\s+track\s+by\s+([\s\S]+?))?\s*$/
^^^