0
I’m already detecting when the user presses enter in the input, but how can I capture the text he typed?
HTML
<div ng-app="Insidetv" ng-controller="ListaController">
@foreach($listas as $lista)
<input value="{{ $lista->descricao }}" type="text" name="descricao" ng-keypress="editName($event)">
@endforeach
</div>
JS
angular.module('Insidetv')
.controller('ListaController', function($scope, $http) {
$scope.editName = function($event){
var keyCode = $event.which || $event.keyCode;
if(keyCode === 13) {
console.log($event);
}
};
});
The input is inside a foreach, so there are several of them, as I can capture the value only of what I write?
– Diego Vieira
put in the rest of the code
– Eduardo Sampaio
Okay, I edited the question. Basically the input is inside a foreach.
– Diego Vieira
@Diegovieira replaces the foreach with ng-repeat, with
track by $index
. Your$scope
will have an array type variable with each input value. Then each input can bengModel
an expression of the kind$scope.model[$index]
– Bernardo Dal Corno