Angular ng-blur in input box not working

Okay, I'm sure I'm missing something, but I don't see it.

I created a fiddle that I would think of by throwing a warning when the input field loses focus, but it does not work and I do not know why.

I was expecting a warning when the user performs the following steps:

  • click input box
  • enter something
  • click somewhere outside the input field

but a warning message is not displayed in these steps.

Of course, someone knows what I'm doing wrong ...?

Here's the code (the same as the fiddle):

<div ng-app> <div ng-controller="MyCtrl"> <form name="myForm"> <input type="text" ng-model="todoText" size="30" name="myInput" ng-blur="validate(myForm)"> </form> </div> </div> function MyCtrl($scope) { $scope.validate = function(form) { alert('blur!'); }; } 
+5
source share
1 answer

This may be your version of angular. Your violin uses 1.0.x I updated you to 1.4.x and its performance:

 <div ng-app='myApp'> <div ng-controller="MyCtrl"> {{santity}} <form name="myForm"> <input type="text" ng-model="todoText" size="30" name="myInput" ng-blur="validate(myForm)"> </form> </div> </div> 

Javascript

 angular.module('myApp', []); angular.module('myApp').controller('MyCtrl', MyCtrl); function MyCtrl($scope) { $scope.santity = 'Hello'; $scope.validate = function(form) { alert('blur!'); }; } 

http://jsfiddle.net/ncapito/LurjLvz7/6/

+3
source

Source: https://habr.com/ru/post/1242742/


All Articles