Reputation: 923
I have a requirement where I need to send modified value alone in the object.
Following is my object:
{
"Code": 200,
"ErrorMessage": null,
"Result": {
"Locations": [{
"LocationName": "Location 1",
"Address": "XYZ",
"City": "Houston",
"State": "TEXAS",
"StateCode": "TX",
"Zipcode": "75201"
},
{
"LocationName": "Location 2",
"Address": "ABC",
"City": "Germantown",
"State": "CALIFORNIA",
"StateCode": "CA",
"Zipcode": "90001"
}]
}
}
I used ng-repeat inorder to display data which has input fields. Now If I modify Location 1 in that Locations Object. I want to send only Location 1 details.
Is it possible to do that in Angular. I am new to angular.
Upvotes: 0
Views: 40
Reputation: 41397
you can use ng-change
to get the modified object
angular.module("app",[])
.controller("ctrl",function($scope){
$scope.changeItem = function(item){
console.log(item.LocationName)
}
$scope.items = {
"Code": 200,
"ErrorMessage": null,
"Result": {
"Locations": [{
"LocationName": "Location 1",
"Address": "XYZ",
"City": "Houston",
"State": "TEXAS",
"StateCode": "TX",
"Zipcode": "75201"
},
{
"LocationName": "Location 2",
"Address": "ABC",
"City": "Germantown",
"State": "CALIFORNIA",
"StateCode": "CA",
"Zipcode": "90001"
}]
}
}
})
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<div ng-repeat="item in items.Result.Locations">
<input ng-model="item.LocationName" ng-change="changeItem(item)"/>
</div>
</div>
Upvotes: 1