0

我想要实现凭证管理API在我的角度应用类型错误:无法构造“PasswordCredential”:“身份证”不能为空

我的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>

我有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(){ 
 

 
      }); 
 
     

但我得到的错误PasswordCredential:ID不能为空

请帮助

+1

[PasswordCredential](https://developer.mozilla.org/en-US/docs/Web/API/PasswordCredential/PasswordCredential)列出了此API的必需字段和可选字段。如果您要将HTML表单的结果插入该API,则需要拥有正确的字段名称。否则,您应该使用正确的字段名构造一个中间对象,从表单的错误字段名称中插入数据。 – James

+0

嗨,詹姆斯,你能详细解释我吗,我是初学者:) –

+0

我从来没有这样做过,我建议你从Mozilla网站上的示例表单开始。 – James

回答

1

而不是做表格样式

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

    }); 

通在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"); 
       }); 

,这应该是所有保存的凭证!

相关问题