【发布时间】:2019-12-22 18:25:44
【问题描述】:
这里发生了一些奇怪的事情还是我错过了其他事情?我有以下模板视图:
user-profile.html
<div id="divUserProfile" ng-controller="userProfileController">
<h1>User Profile</h1>
<fieldset>
<legend>Organizational Information</legend>
<table>
<tr>
<td>
<label>Email Address</label>
<label id="lblEmail" class="label-value">{{email}}</label>
</td>
<td>
<label>Contact Number</label>
<input id="txtContactNo" type="text" value="{{contactNumber}}">
</td>
</tr>
</table>
</fieldset>
</div>
index.js
var app = angular.module("myApp", ["ngRoute"])
.config( // $routeProvider config here... )
.controller("userProfileController", function ($scope) {
console.log("This is userProfileController!");
firebase.auth().onAuthStateChanged(function (user) {
if (user) {
console.log("User = " + user.email); // User does exist and singed in!
$scope.email = user.email; // Email not rendered!
console.log("$scope.email = " + $scope.email); // It does contain my email address!
} else {
console.log("User = " + user);
}
});
});
问题:{{email}} 未渲染!但如果您硬编码 $scope.email = "ee@eee.com";,它就会显示出来!另外,如果你console.log($scope.email),它确实包含我登录的电子邮件地址但从未呈现,为什么???事实上,我在<fieldset> 上填充了更多标签,并且所有标签都使用相同的$scope 正确呈现,除了分配给 Firebase 的user.email 的标签,为什么?我尝试将onAuthStateChanged 替换为var user = firebase.auth().currentUser;,也不起作用。
谁能告诉我它有什么问题?如果您需要我显示更多代码的其他部分,请告诉我,谢谢!
注意:我还注意到谷歌浏览器的自动填充功能已将我的txtContactNo 作为我的登录输入框,不确定这是否与问题有关。
【问题讨论】:
标签: angularjs firebase firebase-authentication