Remember Password with AngularJS and ng-submit

后端 未结 5 1079
说谎
说谎 2020-12-16 11:46

How do I get the browser to ask the user to remember the password when using ng-submit in an AngularJS single page application.

My Form:

5条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-16 12:23

    Your form HTML is a bit confusing.

    
    

    When the form is submitted do you want it to go to /#/dashboard/login or do ng-submit="login()" ? At the moment, the ng-submit is being ignored in favour of the form action. If you want it to go to /#/dashboard/login as a new page, then just remove the ng-submit and onsubmit attributes and it will work as normal.

    If you want it to do ng-submit="login()", then remove the action and onsubmit attributes. Angular automatically prevents form submission when a form with ng-submit does not have an action attribute too. Doing it this way will stop the browser remember password prompt as the form isn't actually submitted anywhere. I guess this is an area where browsers have yet to catch up to the era of the single page application, there's no direct fix for it that I'm aware of.

    A workaround would be to have a separate hidden form in the HTML, set the username/password there to the same as the user enters in main form, and then submit that hidden form to an iframe at the same time as ng-submit is called - have a look at How can I get browser to prompt to save password? for ideas about how to do it.

提交回复
热议问题