How does ng-repeat parse the source expression?












1














[...Array(4).keys()] is valid javascript (ES6) for generating [0,1,2,3].



<span ng-repeat="i in [0,1,2,3]"> works as expected in angularJS but NOT <span ng-repeat="i in [...Array(4).keys()]">.



Nor does <span ng-repeat="i in $eval('[...Array(4).keys()]')">.



So how is the angular engine parsing the expression such that former works but not the latter?



FWIW, the exception starts as:




 ```
angular.js:9037 Error: [$parse:syntax] http://errors.angularjs.org/undefined/$parse/syntax?p0=.&p1=not%20a%20primary%20expression&p2=2&p3=%5B...Array(4).keys()%5D&p4=...Array(4).keys()%5D
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:6:453
at Ya.throwError (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:152:398)
...



```










share|improve this question
























  • docs.angularjs.org/guide/expression
    – JB Nizet
    Nov 23 '18 at 23:01










  • Read AngularJS Developer Guide - AngularJS Expressions vs. JavaScript Expressions. If you want to run more complex JavaScript code, you should make it a controller method and call the method from your view. Then it will be easier to understand, debug, test, and maintain.
    – georgeawg
    Nov 23 '18 at 23:34












  • Yes I read that and I understand there are other ways of doing it, but I would like to understand why the $eval(...) doesn't work in particular, and if there is a way to harness the full capabilities of JS within AngularJS expressions.
    – Dylan Nicholson
    Nov 24 '18 at 0:05






  • 1




    $eval() takes an expression as argument, which is parsed the same way, and thus follows the same rules as all the other angular expressions. Angular expressions look like JS expressions, but they're not. You can only use what AngularJS supports/allows.
    – JB Nizet
    Nov 24 '18 at 0:38
















1














[...Array(4).keys()] is valid javascript (ES6) for generating [0,1,2,3].



<span ng-repeat="i in [0,1,2,3]"> works as expected in angularJS but NOT <span ng-repeat="i in [...Array(4).keys()]">.



Nor does <span ng-repeat="i in $eval('[...Array(4).keys()]')">.



So how is the angular engine parsing the expression such that former works but not the latter?



FWIW, the exception starts as:




 ```
angular.js:9037 Error: [$parse:syntax] http://errors.angularjs.org/undefined/$parse/syntax?p0=.&p1=not%20a%20primary%20expression&p2=2&p3=%5B...Array(4).keys()%5D&p4=...Array(4).keys()%5D
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:6:453
at Ya.throwError (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:152:398)
...



```










share|improve this question
























  • docs.angularjs.org/guide/expression
    – JB Nizet
    Nov 23 '18 at 23:01










  • Read AngularJS Developer Guide - AngularJS Expressions vs. JavaScript Expressions. If you want to run more complex JavaScript code, you should make it a controller method and call the method from your view. Then it will be easier to understand, debug, test, and maintain.
    – georgeawg
    Nov 23 '18 at 23:34












  • Yes I read that and I understand there are other ways of doing it, but I would like to understand why the $eval(...) doesn't work in particular, and if there is a way to harness the full capabilities of JS within AngularJS expressions.
    – Dylan Nicholson
    Nov 24 '18 at 0:05






  • 1




    $eval() takes an expression as argument, which is parsed the same way, and thus follows the same rules as all the other angular expressions. Angular expressions look like JS expressions, but they're not. You can only use what AngularJS supports/allows.
    – JB Nizet
    Nov 24 '18 at 0:38














1












1








1







[...Array(4).keys()] is valid javascript (ES6) for generating [0,1,2,3].



<span ng-repeat="i in [0,1,2,3]"> works as expected in angularJS but NOT <span ng-repeat="i in [...Array(4).keys()]">.



Nor does <span ng-repeat="i in $eval('[...Array(4).keys()]')">.



So how is the angular engine parsing the expression such that former works but not the latter?



FWIW, the exception starts as:




 ```
angular.js:9037 Error: [$parse:syntax] http://errors.angularjs.org/undefined/$parse/syntax?p0=.&p1=not%20a%20primary%20expression&p2=2&p3=%5B...Array(4).keys()%5D&p4=...Array(4).keys()%5D
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:6:453
at Ya.throwError (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:152:398)
...



```










share|improve this question















[...Array(4).keys()] is valid javascript (ES6) for generating [0,1,2,3].



<span ng-repeat="i in [0,1,2,3]"> works as expected in angularJS but NOT <span ng-repeat="i in [...Array(4).keys()]">.



Nor does <span ng-repeat="i in $eval('[...Array(4).keys()]')">.



So how is the angular engine parsing the expression such that former works but not the latter?



FWIW, the exception starts as:




 ```
angular.js:9037 Error: [$parse:syntax] http://errors.angularjs.org/undefined/$parse/syntax?p0=.&p1=not%20a%20primary%20expression&p2=2&p3=%5B...Array(4).keys()%5D&p4=...Array(4).keys()%5D
at https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:6:453
at Ya.throwError (https://ajax.googleapis.com/ajax/libs/angularjs/1.2.0/angular.min.js:152:398)
...



```







angularjs ecmascript-6






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 23:35









georgeawg

32.9k104967




32.9k104967










asked Nov 23 '18 at 22:47









Dylan NicholsonDylan Nicholson

885416




885416












  • docs.angularjs.org/guide/expression
    – JB Nizet
    Nov 23 '18 at 23:01










  • Read AngularJS Developer Guide - AngularJS Expressions vs. JavaScript Expressions. If you want to run more complex JavaScript code, you should make it a controller method and call the method from your view. Then it will be easier to understand, debug, test, and maintain.
    – georgeawg
    Nov 23 '18 at 23:34












  • Yes I read that and I understand there are other ways of doing it, but I would like to understand why the $eval(...) doesn't work in particular, and if there is a way to harness the full capabilities of JS within AngularJS expressions.
    – Dylan Nicholson
    Nov 24 '18 at 0:05






  • 1




    $eval() takes an expression as argument, which is parsed the same way, and thus follows the same rules as all the other angular expressions. Angular expressions look like JS expressions, but they're not. You can only use what AngularJS supports/allows.
    – JB Nizet
    Nov 24 '18 at 0:38


















  • docs.angularjs.org/guide/expression
    – JB Nizet
    Nov 23 '18 at 23:01










  • Read AngularJS Developer Guide - AngularJS Expressions vs. JavaScript Expressions. If you want to run more complex JavaScript code, you should make it a controller method and call the method from your view. Then it will be easier to understand, debug, test, and maintain.
    – georgeawg
    Nov 23 '18 at 23:34












  • Yes I read that and I understand there are other ways of doing it, but I would like to understand why the $eval(...) doesn't work in particular, and if there is a way to harness the full capabilities of JS within AngularJS expressions.
    – Dylan Nicholson
    Nov 24 '18 at 0:05






  • 1




    $eval() takes an expression as argument, which is parsed the same way, and thus follows the same rules as all the other angular expressions. Angular expressions look like JS expressions, but they're not. You can only use what AngularJS supports/allows.
    – JB Nizet
    Nov 24 '18 at 0:38
















docs.angularjs.org/guide/expression
– JB Nizet
Nov 23 '18 at 23:01




docs.angularjs.org/guide/expression
– JB Nizet
Nov 23 '18 at 23:01












Read AngularJS Developer Guide - AngularJS Expressions vs. JavaScript Expressions. If you want to run more complex JavaScript code, you should make it a controller method and call the method from your view. Then it will be easier to understand, debug, test, and maintain.
– georgeawg
Nov 23 '18 at 23:34






Read AngularJS Developer Guide - AngularJS Expressions vs. JavaScript Expressions. If you want to run more complex JavaScript code, you should make it a controller method and call the method from your view. Then it will be easier to understand, debug, test, and maintain.
– georgeawg
Nov 23 '18 at 23:34














Yes I read that and I understand there are other ways of doing it, but I would like to understand why the $eval(...) doesn't work in particular, and if there is a way to harness the full capabilities of JS within AngularJS expressions.
– Dylan Nicholson
Nov 24 '18 at 0:05




Yes I read that and I understand there are other ways of doing it, but I would like to understand why the $eval(...) doesn't work in particular, and if there is a way to harness the full capabilities of JS within AngularJS expressions.
– Dylan Nicholson
Nov 24 '18 at 0:05




1




1




$eval() takes an expression as argument, which is parsed the same way, and thus follows the same rules as all the other angular expressions. Angular expressions look like JS expressions, but they're not. You can only use what AngularJS supports/allows.
– JB Nizet
Nov 24 '18 at 0:38




$eval() takes an expression as argument, which is parsed the same way, and thus follows the same rules as all the other angular expressions. Angular expressions look like JS expressions, but they're not. You can only use what AngularJS supports/allows.
– JB Nizet
Nov 24 '18 at 0:38












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453632%2fhow-does-ng-repeat-parse-the-source-expression%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53453632%2fhow-does-ng-repeat-parse-the-source-expression%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

Calculate evaluation metrics using cross_val_predict sklearn

Insert data from modal to MySQL (multiple modal on website)