Angular 2 - Form is invalid when browser autofill

前端 未结 7 1909
广开言路
广开言路 2021-01-31 16:48

I have a Login Form which has email and password fields.

I\'ve chosen for browser autofill.

The problems is: When browser autofills login form, both fields are p

相关标签:
7条回答
  • 2021-01-31 17:33

    Had the same problem too. I'm not sure if this is the best way, but I was able to get it to work by adding AfterViewChecked

    import { Component, AfterViewChecked } from "@angular/core";
    
    export class LoginComponent implements AfterViewChecked {
        // Beware! Called frequently!
        // Called in every change detection cycle anywhere on the page
        ngAfterViewChecked() {
            console.log(`AfterViewChecked`);
            if (this.usr.userName) {
                // enable to button here.
                console.log("found username in AfterViewChecked");
            }
        }
    }
    

    or you might be able to try Angular2's other Lifecycle Hooks https://embed.plnkr.co/?show=preview

    0 讨论(0)
提交回复
热议问题