Created
October 23, 2014 18:43
-
-
Save Splaktar/3d2dadb1f31012d14211 to your computer and use it in GitHub Desktop.
Directive to fix input fields that need to support browser autofill such as username and password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @ngDoc directive | |
* @restrict A | |
* @description Add this attribute to input fields that need to support browser autofill such as username and password. | |
*/ | |
main.directive('autoFillSync', function($timeout) { | |
return { | |
require: 'ngModel', | |
restrict: 'A', | |
link: function(scope, elem, attrs, model) { | |
var origVal = elem.val(); | |
$timeout(function () { | |
var newVal = elem.val(); | |
if(model.$pristine && origVal !== newVal) { | |
model.$setViewValue(newVal); | |
} | |
}, 200); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment