TypeError:无法构建' PasswordCredential':' id'一定不能空着

时间:2017-05-31 16:55:50

标签: javascript web service-worker progressive-web-apps credential-manager

我想在我的角应用

中实施凭据管理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>
&#13;
&#13;
&#13;

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

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

            });
            
&#13;
&#13;
&#13;

但是我收到错误PasswordCredential:id不能为空

请帮助

1 个答案:

答案 0 :(得分:2)

而不是做表单样式

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

这应该是保存凭据的全部内容!