Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><a href="https://github.com/angular/angular.js/issues/1460" rel="noreferrer">Apparently this is a known issue with Angular and is currently open</a></p> <p>I'm not sure what you could do here besides some sort of work around like you're trying. It seems you're on the right track. I couldn't get my browser to try to remember a password for your plunk, so I'm not sure if this will work but have a look:</p> <pre class="lang-js prettyprint-override"><code>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 &amp;&amp; origVal !== newVal) { ngModel.$setViewValue(newVal); } }, 500); } } }); </code></pre> <pre class="lang-html prettyprint-override"><code>&lt;form name="myForm" ng-submit="login()"&gt; &lt;label for="username"&gt;Username&lt;/label&gt; &lt;input type="text" id="username" name="username" ng-model="username" auto-fill-sync/&gt;&lt;br/&gt; &lt;label for="password"&gt;Password&lt;/label&gt; &lt;input type="password" id="password" name="password" ng-model="password" auto-fill-sync/&gt;&lt;br/&gt; &lt;button type="submit"&gt;Login&lt;/button&gt; &lt;/form&gt; </code></pre> <p>I think you just need to simplify your approach a bit. The one thing I definitely recommend is to check <code>ngModel.$pristine</code> and make sure you're not overwriting some poor user's input. Also, 3 seconds is probably too long. You shouldn't have to call $apply() in a $timeout, BTW, it should queue a $digest for you automatically.</p> <p><strong>The real catch: Will your browser beat Angular to execution? What about my browser?</strong></p> <p>This is probably an unwinnable war, which is why Angular (or Knockout) hasn't been able to solve it readily. There's no guarantee of the state of the data in your input at the time of the directive's initial execution. Not even at the time of Angular's initialization.... So it's a tricky problem to solve.</p>
 

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