Adeel Khan Adeel Khan - 15 days ago 6
AngularJS Question

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.Values= {
site_name: 'Site name',
street_address: 'Street address',
city: 'City',
state: 'state',
country: 'country',
zip_code: 'zip_code',
phone_number: 'phone_number'
};


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>


enter image description here

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