首页 > 解决方案 > Angular 6 - 触发浏览器“保存登录提示”

问题描述

所以,我已经创建了小型应用程序(学习目的)来管理一些数据。问题是,浏览器没有提示在登录页面上保存登录帐户,因为所有应用程序都是single page app并且我希望我的浏览器提示保存登录帐户。我已经找到了一个可能适合我的答案,但因为我只是学习这个角度 6,我无法真正将它们联系起来。所以这是我的代码。

登录组件.ts

@Component({
    selector: 'app-login',
    templateUrl: './login.component.html',
    styleUrls: ['./login.component.css']
})
export class LoginComponent implements OnInit {
    loginForm : FormGroup;

     username = "";
     password = "";

    constructor(
            public global: GlobalService,
            public messagerService: MessagerService,
            private cookie: CookieService, //persistent
            private router: Router,
            private fb: FormBuilder
        ) {
              this.loginForm = fb.group({
                  username: ["asdsa", Validators.required],
                  password: ["adssa", Validators.required]
              });
           }

    login(){
        var helper = new JwtHelperService();
        if(this.username=='' || this.password=='')
            this.messagerService.alert({
                title: 'Error',
                icon: 'error',
                msg: 'Please fill the forms!'
            });
        else{
            this.global.login(this.username, this.password).subscribe(
                data => {
                    if(data.success=='1'){
                        this.cookie.set('jwtObj', data.jwt, new Date().getSeconds() + 7200, '/');
                        this.global.loginCheck();
                    }
                    else if(data.success == '0'){
                        this.messagerService.alert({
                            title: 'Error',
                            icon: 'error',
                            msg: data.msg
                        });
                    }
                },
            );
        }
    }

    ngOnInit() {
    }

    submitForm(value){
        console.log(value);
    }

}

login.component.html

<eui-panel [title]="'Login Panel'" [collapsible]="true" [bodyStyle]="{padding:'20px'}" style="height:320px;width:400px; margin:auto;margin-top: 25vh">
        <h2>RUC SSO LOGIN</h2>
        <form novalidate #formm [formGroup]="loginForm" (ngSubmit)="submitForm(loginForm)">
            <div style="margin-bottom:10px;">
                <label [for]="t1" align="top">Username:</label>
                <eui-textbox #t1 formControlName="username" iconCls="icon-man" placeholder="username" style="width:100%"></eui-textbox>
            </div>
            <div style="margin-bottom:10px;">
                <label [for]="t2" align="top">Password:</label>
                <eui-passwordbox #t2 formControlName="password" placeholder="password" style="width:100%"></eui-passwordbox>
            </div>
            <div>
                <eui-linkbutton (click)="submitForm(loginForm)">Login</eui-linkbutton>
            </div>
        </form>
</eui-panel>

如何触发浏览器提示?

标签: angularloginlogin-controljquery-easyui

解决方案


好的,我创建了一个简单的示例,在 Firefox stackblitz app URL上进行了测试

stackblitz 编辑器 URL

在此处输入图像描述

编辑:您正在使用easyui,这可能是easyui的问题,但在表单提交和导航到其他组件时保存密码提示。


推荐阅读