类型错误:无法构造“PasswordCredential”:“id”不能为空

Moh*_*ria 1 javascript web credential-manager service-worker progressive-web-apps

我想在我的 Angular 应用程序中实现凭证管理 API

我的login.html 看起来像这样

<div id="login-form" data-ng-form="loginForm" data-ng-controller="LoginFormController">
    <div>
        <input type="text" name="username" placeholder="username" data-ng-model="loginCredentials.username" id="uid" autocomplete="username">
        <input type="password" name="password" placeholder="password" data-ng-model="loginCredentials.password" id="pwd" autocomplete="new-password">
    </div>
    <div>
        <button id="loginButton" data-ng-click="login()">{{'label.button.login' | translate}}</button>
    </div>
    <div data-ng-show="authenticationFailed">
        <p>{{authenticationErrorMessage | translate}}</p>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

我有 LoginFormController 作为我的控制器。在函数内部,我创建了名为 PasswordCredential 的新对象,如下所示

            var form = angular.element('#login-form');
            //console.log(form);
            var cred  = new PasswordCredential(form);
            //store the credentials
            navigator.credentials.store(cred)
            .then(function(){

            });
            
Run Code Online (Sandbox Code Playgroud)

但我收到错误密码凭据:id 不能为空

请帮助

小智 5

而不是做表单样式

var form = angular.element('#login-form');
var cred  = new PasswordCredential(form);
//store the credentials
navigator.credentials.store(cred)
   .then(function(){

   });
Run Code Online (Sandbox Code Playgroud)

传入PasswordCredential对象样式

var cred  = new PasswordCredential({
                id: scope.loginCredentials.username,
                password: scope.loginCredentials.password
            });
//store the credentials
navigator.credentials.store(cred)
                .then(function(){
                    console.log("Done Saving Creds");
                });
Run Code Online (Sandbox Code Playgroud)

这应该是为了保存您的凭据!