Created
July 29, 2014 20:25
-
-
Save rafakato/2b4e333a4e5647994114 to your computer and use it in GitHub Desktop.
AngularJS browser autofill workaround
This file contains hidden or 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
app.directive('autoFillSync', function($timeout) { | |
return { | |
require: 'ngModel', | |
link: function(scope, elem, attrs, ngModel) { | |
var origVal = elem.val(); | |
$timeout(function() { | |
var newVal = elem.val(); | |
if (ngModel.$pristine && origVal !== newVal) { | |
ngModel.$setViewValue(newVal); | |
} | |
}, 500); | |
} | |
} | |
}); |
This file contains hidden or 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
<form name="myForm" ng-submit="login()"> | |
<label for="username">Username</label> | |
<input type="text" id="username" name="username" ng-model="username" auto-fill-sync/> | |
<br/> | |
<label for="password">Password</label> | |
<input type="password" id="password" name="password" ng-model="password" auto-fill-sync/> | |
<br/> | |
<button type="submit">Login</button> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment