Created
December 18, 2013 07:24
-
-
Save pc035860/8018569 to your computer and use it in GitHub Desktop.
AngularJS browser autofill workaround by using a directive http://stackoverflow.com/questions/14965968/angularjs-browser-autofill-workaround-by-using-a-directive
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) { | |
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
AngularJS browser autofill workaround by using a directive
http://stackoverflow.com/questions/14965968/angularjs-browser-autofill-workaround-by-using-a-directive