0

空にすることはできません私のlogin.htmlと、このはTypeError: 'のPasswordCredential' の構築に失敗しました: 'ID' は、私は私の角度アプリで資格管理APIを実装したい

<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を私のコントローラとして持っています。関数の内部で、私はこの

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

 
      }); 
 
     

のようなのPasswordCredentialと呼ばれる新しいオブジェクトを作成した。しかし、私はエラーの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"); 
       }); 

で、これはあなたの資格情報を保存するために、すべての必要があります!

関連する問題