0

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

2
  • Looks like $scope.values is a list but you are using it as an object in ng model Commented Nov 23, 2016 at 8:23
  • i want object.... Commented Nov 23, 2016 at 8:24

2 Answers 2

1
$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.

Sign up to request clarification or add additional context in comments.

12 Comments

Object {} array are blank when i check console.log( $scope.values);
Did you change your ng-model ? Never use capital letters as first letters of a variable name. look, in the td you can see that ng-model="values." instead of ng-model="Values."
Please see my edit. If you do this and your inputs are empty, you didn't bind your controller to your view properly.
there is hard coded values 'Site name', like store but does not store textbox value when i change 'Site namemyname', from textbox
Ok so I don't understand anything you're saying. See this JSFiddle and try to understand what you did wrong.
|
0

You are trying to iterate over an object. Your model should be an array in order to support this. The rest of your code is just fine. Replace your Values with:

 $scope.Values =  [
     {
       site_name: 'Site name',
       street_address: 'Street address',
       city: 'City',
       state: 'state',
       country: 'country',
       zip_code: 'zip_code',
       phone_number: 'phone_number'
    }, 
    { //next object
    }
];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.