Skip to content

Instantly share code, notes, and snippets.

@Splaktar
Created October 23, 2014 18:43
Show Gist options
  • Save Splaktar/3d2dadb1f31012d14211 to your computer and use it in GitHub Desktop.
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
/**
* @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