1
私は、ユーザーが自分の電子メールアドレスを更新できるHTMLページを作成しています。私はFirebaseにユーザーがフォームに入力した電子メールアドレスを更新するイベントリスナーを添付しました。Firebase Update電子メールアドレスHTMLフォーム
以下のコードはエラーを示します。未知の型エラー:HTMLButtonElementでnullのプロパティ 'updateEmail'を読み取ることができません。
updateEmailはFirebaseのドキュメントに表示されるので混乱します。私は行方不明のものがありますか?ご協力いただきありがとうございます!
のJs
"use strict";
(function() {
// get the form elements from HTML
var acctEmail = document.getElementById('acctEmail'),
acctPassword = document.getElementById('acctPassword'),
btnUpdate = document.getElementById('btnUpdate'),
btnDeleteAcct = document.getElementById('btnDeleteAcct'),
auth = firebase.auth(),
user = firebase.auth().currentUser, // get the current user
emailtoval = acctEmail.value, // get the email from acctEmail input field
email = JSON.stringify(emailtoval); // convert email to json string
// update email
btnUpdate.addEventListener('click', function (e) {
user.updateEmail(email).then(function() {
// Update successful.
}, function(error) {
console.log(error);
});
});
})(); // end Js file wrapper
は、ここでHTMLフォームの:
<!DOCTYPE html>
<html>
<head>
<!-- head include -->
<% include includes/head.ejs %>
</head>
<body id="accountbody">
<!-- header include -->
<% include includes/header.ejs %>
<main>
<h1> Manage Your Account </h1>
<!-- begin account details form -->
<h2>Update your account</h2>
<div class="updateacctform">
<input id="acctEmail" type="email" placeholder="Email">
<input id="acctPassword" type="password"
placeholder="Password">
<button id="btnUpdate" class="updateacctbtn">Update
</button>
</div>
<div>
<h2>Delete your account</h2>
<button id="btnDeleteAcct" class="deleteacctbtn"> Delete
Account
</button>
</div>
</main>
<!-- footer include -->
<% include includes/footer.ejs %>
<!-- Js files -->
<script src="javascripts/account.js"></script>
</body>
</html>
ありがとうございました。私はそれを働かせた。私はあなたの答えの編集としてここに投稿します。 。 – greynolds
firebase.auth()onAuthStateChanged(関数(firebaseUser){ (firebaseUser){ VAR NEWEMAIL =のdocument.getElementById( 'acctEmail')の値であれば、。。 VARユーザー= firebase.auth()あるCurrentUser; ユーザ。 。updateEmail(NEWEMAIL).then(関数(){//成功 user.sendEmailVerification()を(関数(){// メール}を送信し、機能(エラー){//エラー }); }、関数(エラー){ //エラー }); } }); – greynolds