2017-04-18 6 views
0

私は、AngularJSでFirebaseを使用し、index.htmlのサイドナビゲーションバーを使用して単一ページアプリケーションを作成しています。

ログイン後、ユーザー名はサイドナビゲーションバーに表示しますが、コントローラの現在のページで$スコープが機能していることを確認します。

scotchApp.controller('mainController', function($scope) { 
    $scope.validateLogin = function() 
    { 
     var email = $scope.login.userName + "@xyz.co"; 
     var password = $scope.login.password; 
     firebase.auth().signInWithEmailAndPassword(email, password).catch(function(error) { 
      $scope.message = "please enter the correct details"; 
     }); 
     firebase.auth().onAuthStateChanged(function(user) 
     { 
      if(user) 
      { 
       $scope.usermobile = $scope.login.userName; 
       window.location.assign("/#/equipment"); 
      } 
     }); 
    } 
    $scope.message = ''; 
}); 
+0

私はこの作品を理解していません: "コントローラの現在のページで$スコープが動作しています。" - 明確にすることはできますか? –

+0

なぜ 'window.location.hash =" /#/ equipment "を使わないのですか? ' –

+0

@CliveSeebregts 実際に$ scopeは現在のルーティングページ で動作しますが、そのルーティングコントローラ –

答えて

0

mainControllerあなたは認証の変更をリッスンする必要はありませんでのでdocsで説明したように、現在のユーザーはfirebase.auth().currentUserで利用可能です。

新しいリスナーにユーザーがログインしようとしますが、あなたが実際にしたいことは1つのログイン成功に対応するためで、これだけの呼び出しであなたの星座に thenを追加するたびに添付されているあなたのコードで

firebase.auth().signInWithEmailAndPassword(email, password) 
    .then(function (user) { 
    console.log('the logged in user: ', user); 
    // Go to the other route here. 
    // It is recommended to use the router instead of "manually" changing `window.location` 
    }) 
    .catch(function(error) { 
    $scope.message = "please enter the correct details"; 
    }); 
関連する問題