Search code examples
javascriptangularjsangularjs-directiveangularjs-scope

how to save textbox values in scope variable angularjs


i want store textbox value in my Values variable but its not save i don't know why anyone help me please??? i am new in angularjs that's why i am here please help me i want store values from textbox, i enter my textbox ff fff see below image, but i check my console file its show 'Site name' i think its get from my hard coded value but i want data from textbox

     $scope.form =  {
        site_name: 'Site name',
        street_address: 'Street address',
        city: 'City',
        state: 'state',
        country: 'country',
        zip_code: 'zip_code',
        phone_number: 'phone_number'

      };   
       $scope.addRow = function() {
        $scope.i++;
        $scope.array = [];
        for(var i = 0; i < $scope.i; i++) {
            $scope.array.push(i);
        }
    }  
        var checkprofile = $scope.Profile.id;
         $(".alert").hide();    
          $scope.updateProfile = function () {   

               console.log( 'updateProfile');
             console.log( $scope.form);   
 $scope.Profile.addresses.push($scope.form);
            $scope.tempObject={full_name:$scope.Profile.full_name,
              mobile_number:$scope.Profile.mobile_number,
             company_name:$scope.Profile.company_name,
             designation: $scope.Profile.designation,    
            addresses: $scope.Profile.addresses,

            payment_info: $scope.Profile.payment_info

           };  

           $http.put(properties.customerupdate_path + "/"+checkprofile,$scope.tempObject).success(function (response) { 
           // window.location.href = '/customerprofile';
                });
            }    

i click button after enter values 'ff' 'ff' 'ff' in my textboxes ...below code does not get data from textbox its get my above values i don't know why

  $scope.updateProfile = function () {    
           console.log( 'updateProfile');
         console.log( $scope.Values );   

//result --> [Object { site_name="Site name", street_address="Street address", city="City", more...}]

}

HTML//

 <tr ng-repeat="lines in array">
    <td><input type="text" class="form-control" id="inputDefault"  ng-model='Values.site_name ' name='site_name'></td>
    <td><input type="text" class="form-control" id="inputDefault"  ng-model='Values.street_address ' name='street_address'></td>
    <td><input type="text" class="form-control" id="inputDefault"  ng-model='Values.city ' name='city'></td>
    <td><input type="text" class="form-control" id="inputDefault"  ng-model='Values.state ' name='state'></td>
    <td><input type="text" class="form-control" id="inputDefault"  ng-model='Values.country ' name='country'></td>
    <td><input type="text" class="form-control" id="inputDefault"  ng-model='Values.zip_code ' name='zip_code'></td>
    <td><input type="text" class="form-control" id="inputDefault"  ng-model='Values.phone_number ' name='phone_number'></td>                                        
</tr>

Update Profile

enter image description here


Solution

  • $scope.values = {
        site_name: 'Site name',
        street_address: 'Street address',
        city: 'City'
    };
    
    <tr>
        <td><input type="text" class="form-control" id="inputDefault"  ng-model='values.site_name ' name='site_name'></td>
        <td><input type="text" class="form-control" id="inputDefault"  ng-model='values.street_address ' name='street_address'></td>
        <td><input type="text" class="form-control" id="inputDefault"  ng-model='values.city ' name='city'></td>
        <td><input type="text" class="form-control" id="inputDefault"  ng-model='values.state ' name='state'></td>
        <td><input type="text" class="form-control" id="inputDefault"  ng-model='values.country ' name='country'></td>
        <td><input type="text" class="form-control" id="inputDefault"  ng-model='Values.zip_code ' name='zip_code'></td>
        <td><input type="text" class="form-control" id="inputDefault"  ng-model='values.phone_number ' name='phone_number'></td>
    </tr>
    

    You don't use an Array to store your variable, but an object.