我正在使用AngularJS和Meteor,我遇到了麻煩與身份驗證,我使用帳戶密碼包以便使用帳戶包方法但實現我的自己的UI。
至於現在我有這個在我的ng.html(視圖)文件:
ng-if當更新控制器的值時出現問題
<div ng-if="$auth.currentUser">I am visible only for logged in users!
<br>
{{ $auth.currentUser.emails }}
<form>
<input type = "submit" value = "Logout" ng-click = "logout();">
</form>
</div>
<div ng-if="!$auth.currentUser">
<input type="email" name="loginEmail" ng-model = "loginEmail">
<input type="password" name="loginPassword" ng-model = "loginPassword">
<input type = "submit" value = "Login" ng-click = "login(loginEmail,loginPassword);" >
</div>
所以,如果有登錄用戶,在$ auth.currentUser的值不爲空,並在第一個div應該可見。 存在的主要問題是,我調用$ parent.login(...)使用控制器來做驗證,我有這個在我的控制器:
$scope.login = function(loginEmail, loginPassword) {
//event.preventDefault();
Meteor.loginWithPassword(loginEmail, loginPassword);
//location.reload();
//$route.reload();
}
,後登錄功能結束後,$ AUTH .currentUser變量不爲null,沒關係,現在我們應該看到另一個div,但是,ng-if不會再檢查$ auth.currentUser的值,直到發生什麼事情,像我按下按鈕兩次或使用我的一些網頁功能,例如在翻過去時改變一些div的樣式或屬性。
所以我的問題是,有沒有辦法讓ng-if在某些方法結束後再次檢查值(因爲這種情況也發生在Register和Logout方法中)或者變量已更新?
感謝您的時間&答案:)
我還沒有和流星的工作,但對角是你綁定NG-如果對$範圍應該工作屬性發生變化時的屬性。 –