I have a simple ng-repeat list, in which i am assigning current list item value to another property on the controller as follows:
<li ng-repeat="num in list">
<input type="text" ng-init="value = num" ng-model="value" />
<button type="button" class="btn btn-primary" ng-click="save()">Save</button>
</li>
But when i click the Save button i get default value set for $scope.value. I expect the value for the particular input text to be displayed.
Here is the controller:
angular.module('myApp', [])
.controller('MyController', function($scope){
$scope.value = false;
$scope.list = [0, 1, 2, 3, 4];
$scope.save = function() {
alert($scope.value);
}
});
How can i access the updated value of a input item in my controller on save function call.
Here is the plunker for the same: plnkr
Update: I am expecting the value to be fetched to controller without passing it as a parameter.
ng-click="save(value)"
accept the parameter and then perform your operation – Wormwoodng-model="$parent.value"
– Wormwood