Angular Error assigning "*" to a variable declared in the scope

4

My problem is as follows, I have declared the following variable in the scope:

  $scope.submit={
     next:"",
     formparams:"",
     value:""
  };

In my HTML I have:

  <div>
   <div ng-repeat="opcion in menu.opciones"><label> Opcion: </label>
     <input id="{{opcion.opcion}}" type="radio" name=grupo
      value="{{opcion.Submit}}+{{opcion.opcion}}" ng-model="submit.next"
      ng-change="submit.value={{opcion.opcion}}" ng-required="true"required> {{opcion.opcion}}                          
    </input>
</div></div>

In the arrangement of options come an arrangement as follows {1,2,3,4,*,#}

When I select any of the options that are numeric on the radio, everything is perfect, but when I select the example "*" in the browser console I see the following error:

angular.js:9419 TypeError: a is not a function
at OPERATORS.* (http://192.168.0.3:8080/MobilTest/lib/angular.js:9515:44)
at http://192.168.0.3:8080/MobilTest/lib/angular.js:10041:35
at Scope.$eval (http://192.168.0.3:8080/MobilTest/lib/angular.js:11961:28)
at http://192.168.0.3:8080/MobilTest/lib/angular.js:16943:13
at http://192.168.0.3:8080/MobilTest/lib/angular.js:16784:11
at Array.forEach (native)
at forEach (http://192.168.0.3:8080/MobilTest/lib/angular.js:303:11)
at $setViewValue (http://192.168.0.3:8080/MobilTest/lib/angular.js:16782:7)
at http://192.168.0.3:8080/MobilTest/lib/angular.js:16284:14
at Scope.$eval (http://192.168.0.3:8080/MobilTest/lib/angular.js:11961:28)(anonymous function) @ angular.js:9419(anonymous function) @ angular.js:6843(anonymous function) @ angular.js:16786forEach @ angular.js:303$setViewValue @ angular.js:16782(anonymous function) @ angular.js:16284Scope.$eval @ angular.js:11961Scope.$apply @ angular.js:12061(anonymous function) @ angular.js:16283(anonymous function) @ angular.js:2613forEach @ angular.js:310eventHandler @ angular.js:2612

And the value of the option "*" is not assigned to the variable.

Thank you very much for your prompt help.

    
asked by Ivan Fontalvo 29.03.2016 в 05:24
source

2 answers

3

The error was that when placing the * it was being interpreted as an arithmetic operator, not as a value of type string. when creating the fix, then ['1','2','3','*'] the code works as it is.

    
answered by 29.03.2016 / 06:14
source
2

The problem is in the array:

{1,2,3,4,*,#}

With the numbers it works without problems, because they are interpreted as an integer value, but if you want the value of the option to be "*", you have to quote the asterisk; if not, it will be interpreted as the multiplication operator and it will create the problems you are seeing. Similarly, you have to quote the pad to be interpreted as a string and avoid problems:

{1,2,3,4,"*","#"}
    
answered by 29.03.2016 в 06:14