I would like each one of my list items to be editable via the input. Clicking on the list item fills in the input, but how do I then specify what item to update? I have the $watch working.
Any help is appreciated.
I have a plunker: https://plnkr.co/edit/mslpklTaStKEdo64FpZl?p=preview
Here is the code:
<body ng-app="myApp">
<div ng-controller="MyController">
<ul ng-repeat="item in collection">
<li ng-click="edit(item.name)">{{item.name}}</li>
</ul>
<input name="myinput" ng-model="myinput" />
</div>
</body>
JS:
var app = angular.module('myApp', [])
.controller('MyController', function($scope, $http) {
$scope.collection = [
{name:'foo'},
{name:'bar'},
{name:'foobar'},
{name:'barfoo'},
];
$scope.edit = function(current_name) {
$scope.myinput = current_name;
console.log(current_name);
}
$scope.$watch('myinput', function(NewValue, OldValue) {
console.log(NewValue);
}, true);
})