AngularJS: Get input value in keypress

0

I'm already detecting when the user presses enter on input , but how can I capture the text that 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);
        }
    };
});
    
asked by anonymous 21.01.2018 / 16:55

1 answer

0

follow the example

    

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="/angular.min.js"></script>
    <script>
        const app = angular.module('Insidetv', []);

        app.controller('ListaController', [
            '$scope',
            function($scope) {
                $scope.editName = function($event, model) {
                    var keyCode = $event.which || $event.keyCode;

                    if (keyCode === 13) {
                        console.log(model);
                        console.log($event);
                    }
                };

            }
        ]);
    </script>
</head>

<body>
    <div ng-controller="ListaController">
        <input type="text" name="descricao" ng-model="$scope.model" ng-keypress="editName($event,$scope.model)">
    </div>
</body>

</html>
    
21.01.2018 / 19:47