Search code examples
angularjsngmodel

Angular update ng-model without quotations marks


Here is my code : JS:

 $scope.gamma = {
        0 : 2
    };
    $scope.matrix = {
        1 : 21, 2 : 25, 3 : 21, 4 : 85, 5 : 798, 6 : 4, 7 : 51, 8 : 224, 9 : 63
    };
    $scope.update_layers = function(gamma, gvalue, matrix, mvalue){

        $scope.gamma = gamma;
         if(gvalue){
                $scope.gamma.gvalue = parseInt(gvalue)

                for(var i in $scope.gamma){
            $scope.gamma[i] = parseInt($scope.gamma[i]);
        }
        }

        if(mvalue){
                $scope.matrix.mvalue = parseInt(mvalue)
        }

HTML:

{{gamma}}{{matrix}}
                    <br />
               gamma : <span ng-repeat="(g, value) in gamma"> <input class="form-control" style="margin:5px;width:100px;text-align:center;display:inline-block;text-align:center"  ng-model="gamma[g]"></span>
                        <br />
               matrix : <span ng-repeat="(m, value) in matrix"> <input class="form-control" style="margin:5px;width:100px;text-align:center;display:inline-block;text-align:center"  ng-model="matrix[m]"></span>


                    <button class="btn" ng-click="update_layers(gamma, gamma.value, matrix, matrix.value)">update</button>

I want to show: "1":21 instead of "1":"21" Here my plnkr and my effors : http://plnkr.co/edit/LFvqgeCtOWv4OGxiDDuY?p=preview


Solution

  • Add type="number" to your input fields. E.g.

    <input type="number" class="form-control" style="margin:5px;width:100px;text-align:center;display:inline-block;text-align:center" ng-model="matrix[m]">