Firebaseデータベースにデータを送信し、$ state.goなどの他のアクションを行うようにデータが更新されるまで待ちます。
値が更新されるまでFirebaseが待機する
FirebaseとAngularJsを使ってどうすればいいですか?
このコードの私の部分:
var ref_achats_offres = firebase.database().ref('achats_offres');
var key_achats_offres = ref_achats_offres.push().key;
var ladate = moment().format();
var accountId = $localStorage.accountId;
var push_achats_offres = ref_achats_offres.child(key_achats_offres).set({
cout: cout,
ajout_le: ladate,
active:true,
accounts: accountId,
id_offre : id_offre,
unique_code: code
});
var ref_offres = firebase.database().ref('offres');
ref_offres.child(id_offre).child('achats_offres').child(key_achats_offres).set(true);
var ref_accounts = firebase.database().ref('accounts');
ref_accounts.child(accountId).child('achats_offres').child(key_achats_offres).set(true);
firebase.database().ref('accounts').child(accountId).child('credits').transaction(function(credits) {
return credits - cout;
});
$scope.modal2.hide();
Utils.message(Popup.checkIcon, Popup.achatOffreEffectue);
$state.go('mes_achats');
私は何も知りませんAngularについてしかし、あなたが探しているものは、firebaseの "トランザクション"です:https://firebase.google.com/docs/database/web/save-data#save_data_as_transactions トランザクションのコールバックの方法はちょっと複雑ですが有効です非常に柔軟な使い方をするには、https://firebase.google.com/docs/reference/js/firebase.database.Reference#transaction – Sistr
の詳細を読む必要があります。AngularFireのルーティングのベストプラクティスに関するアドバイスも参照してください。 ')[ここ](https://github.com/firebase/angularfire/blob/master/docs/guide/user-auth.md#authenticating-with-routers)。 – Kato
@Katoあなたが言っていることは分かりません!私は自分のルートに間違ったことをしましたか?ありがとうございました ! –