2016-07-10 10 views
0

私は、データベース用にIonic.io(バージョン1)とFirebase(最新バージョン、私は信じている)を使って最初のモバイルアプリケーションを構築しています。登録に成功すると、あなたのプロフィールを記入する別のページにサイトがリダイレクトされるように、登録ページを設定しようとしています。しかし、サインアップボタンを押すと、ユーザーは正常に作成されますが、$ location.path( '...')は何もしません(コンソールには 'Redirecting'が表示されますが、下記参照)。もう一度クリックすると、ページが期待どおりにリダイレクトされます。

$ scopeを導入するなどいくつかのことを試しましたが、サービス/工場内で$ scopeを使用することはできないと私は信じていました。私はまた、パスの前に#を追加しようとしました。 $ location.url()を使っても役に立ちません。私はタイムアウトを導入することで問題を解決することができましたが、これはちょっとハッキリしています。なぜこの問題が発生しているのですか?

ありがとうございます!

サービス:

signupEmail: function(newEmail, newPassword, newType) { 
      var user; 
        firebase.auth().createUserWithEmailAndPassword(newEmail, newPassword) 
         //{email: newEmail, 
         //password: newPassword,} 
        .then(function(success) { 
         console.log("Successfully signed up!"); 
         console.log(success); 
       user = firebase.auth().currentUser; 
       console.log("User....") 
       console.log(user) 
      }).then(function() { 
       firebase.database().ref('users/' + user.uid).set({ 
       type: "..." 
       })  
       console.log("Redirecting..."); 
       $timeout(function(){ 
       $location.path("/profile"); 
       },0); 
      }) 
        .catch(function(error) { 
         console.log(error.code) 
         console.log(error.message) 
        }) 
       }, 

コントローラー:

function SignupCtrl($scope, AuthService) { 
    $scope.data = {}; 

    $scope.createUser = function() { 
     var newEmail = $scope.data.email; 
     var newPassword = $scope.data.password; 
     var newType = $scope.data.type; 
     AuthService.signupEmail(newEmail, newPassword, newType) 
    }; 
} 

答えて

1
AuthService.signupEmail(newEmail, newPassword, newType) 
.then(function(_user) { 
    $state.go('profile', _user) 
}, function(_error) { 
    console.log(_error) 
}); 

がサービスを持っていることは、作業の約束...

signupEmail: function(newEmail, newPassword, newType) { 
    var user; 

    return firebase.auth().createUserWithEmailAndPassword(newEmail, newPassword) 
      .then(function(success) { 
       console.log("Successfully signed up!"); 
       console.log(success); 
       user = firebase.auth().currentUser 
       return user; 
      }).then(function(_user) { 
       firebase.database().ref('users/' + user.uid).set({}) 
       return user; 
      }) 
    }, 
+0

を返します。ありがとう!しかし、私はあなたのコードを完全に理解していません。なぜアンダースコア(_user、_error)を導入していますか?また、コントローラの関数(_error)ビット - 代わりに私はちょうどサービスから.catchをコピーし、これも同様に動作するようです。彼らは同等か私は何かを逃していますか? – LondonBoy

+0

私はちょうどそれを行うので、私は関数へのパラメータは何かを知っている.. –

関連する問題