Search code examples
javascriptangularjsgruntjsgrunt-contrib-uglify

for (let .. of ) error in grunt build


I have an Angular aplication and in some controller have the following code:

for (let subForm of $scope.info.subForms) {
    var index = $scope.data.fields.indexOf(subForm);
    $scope.data.subForms.push($scope.data.fields.splice (index + 1 , (subForm.data * subForm.filesLength)));
};
......

when run my aplication using grunt serve the aplication run normal without errors but when generete the deploy code using the command grunt build get the following error:

Unexpected token name «subForm», expected punc «;». 
Line 1410 in .tmp/concat/scripts/scripts.js
Use --force to continue.

is a grunt error? I have grunt v0.4.5 thanks for your help

EDIT

In the following link link could see documentation about the syntax


Solution

  • Try using this

    angular.foreach($scope.info.subForms, function(subForm) {
        var index = $scope.data.fields.indexOf (subForm);
        $scope.data.subForms.push($scope.data.fields.splice (index + 1 , (subForm.data * subForm.filesLength)));
    })
    

    Your inside code maybe can need a refactor. If you share the use, I can try help you.

    Another solution

    for (let index = 0; index < subForm of $scope.info.subForms.length; index++) {
        $scope.data.subForms.push($scope.data.fields.splice (index + 1 , (subForm.data * subForm.filesLength)));
    };