Note that there are some explanatory texts on larger screens.

plurals
  1. POAngularJS 1.2.0-rc.2 vs 1.2.0 element binding
    primarykey
    data
    text
    <p>I recently upgraded my AngularJS Framework from 1.2.0-rc.2 to the 1.2.0 release and came upon a strange issue that I haven't figured out a way around. The issue I had previous resolved was forcing an input field to fire on the on-blur event instead of the on-change event. The code for the directive I originally used was:</p> <pre><code>angular.module('app', []).directive('ngModelOnblur', function() { return { restrict: 'A', require: 'ngModel', link: function(scope, elm, attr, ngModelCtrl) { if (attr.type === 'radio' || attr.type === 'checkbox') return; elm.unbind('input').unbind('keydown').unbind('change'); elm.bind('blur', function() { scope.$apply(function() { ngModelCtrl.$setViewValue(elm.val()); }); }); } }; }); </code></pre> <p>which is just using the suggestion found here <code>https://groups.google.com/forum/?fromgroups#!searchin/angular/change$20blur/angular/LH0Q1A-qTVo/eyVIjJsFZGcJ</code></p> <p>I've created two jsFiddles, one using AngularJS 1.2.0-rc.2 <a href="http://jsfiddle.net/Aaronias/dw9Xy/" rel="nofollow">here</a>, and the other using AngularJS 1.2.0 <a href="http://jsfiddle.net/Aaronias/taZN7/" rel="nofollow">here</a>.</p> <p>The <code>ngModleOnBlur</code> directive should remove the <code>'change'</code> binding from the <code>&lt;input&gt;</code> element and add an explicit <code>'blur'</code> binding.</p> <p>You'll notice that the fiddles behave differently, like the binding for <code>elm.bind('blur', function(){...})</code> isn't actually being bound properly to the element, and it seems that <code>elm.unbind('input').unbind('keydown').unbind('change')</code> doesn't work the same in 1.2.0.</p> <p>I am aware of the new <code>ng-blur</code> directive, but in my case I can't use that directly, but need to manually override the events bound to the element. If someone could post a working jsfiddle of how to manually override the events bound to an element, and/or explain why this has changed from 1.2.0-rc.2 to 1.2.0, that would be incredibly helpful.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload