How to use the Angular onBlur? [duplicate]

1

I want the console value I entered in the cep field to appear in the input after the field loses focus. However, my code is not doing this.

html:

<body ng-controller="appController">
<div align="center">
    <form>
        <label>CEP </label><br>
        <input type="text" ng-model="endereco.cep" ng-blur="pegaCep(endereco)"><br>
        <label>Estado </label><br>
        <input type="text" ng-model="endereco.estado"><br>
    </form>
</div>
</body>

Angular:

app.controller('appController', function ($scope, $http){
    var pegaCep = function (data) {
        console.log(data);
    }
    pegaCep()
});
    
asked by anonymous 20.01.2016 / 03:09

1 answer

1

var app = angular.module('myApp', []);

app.controller('appController', function ($scope, $http){
  $scope.pegaCep = function () {
    console.log($scope.endereco.cep);
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script><bodyng-app='myApp'ng-controller="appController">
<div   align="center">
    <form>
        <label>CEP </label><br>
        <input type="text" ng-model="endereco.cep" ng-blur="pegaCep()"><br>
        <label>Estado </label><br>
        <input type="text" ng-model="endereco.estado"><br>
    </form>
</div>
</body>
    
20.01.2016 / 13:09