2

We have a login form with email and password field.

FF has a feature to save username and password.

So once I enter it and then save the password.

Next time I come for login then form is auto-filled by browser without any click, bind, change or blur event.

So when i submitted this correctly filled form, data is not placed in model i.e $scope.

I have to write query code in submit to get value of email and password fields.

Do we have anyway in which I can avoid using jQuery to get the values?

Well my real question is ?

In General - do we have any option in angular that will get (refresh) the values again from dom.

Something like $scope.usr.email.refresh or angular.refresh(usr.email.refresh) or

may be best return $scope.usr.email.refresh = angluar.get('.email')

instead of making $scope.usr.email.refresh = $('.email').val();

I had faced similar problem when using a checkbox also, where checkbox state is set using some expersion but ng-model does not take state or expressions directly.

Amol Ghotankar
  • 2,008
  • 5
  • 28
  • 42

1 Answers1

1

use below autofill directive

app.directive("autofill", function () {
    return {
        require: "ngModel",
        link: function (scope, element, attrs, ngModel) {
            scope.$on("autofill:update", function() {
                ngModel.$setViewValue(element.val());
            });
        }
    }
});
harishr
  • 17,807
  • 9
  • 78
  • 125