Javascript Firebase响应后Angular.js页面未更新
在上面的代码中,当我单击提交时,我的注册函数运行,然后在Javascript Firebase响应后Angular.js页面未更新,javascript,angularjs,firebase,firebase-authentication,Javascript,Angularjs,Firebase,Firebase Authentication,在上面的代码中,当我单击提交时,我的注册函数运行,然后在firebase.auth().createUserWithEmailAndPassword运行,但在我从firebase.auth().createUserWithEmailAndPassword($scope.user.email,$scope.user.password)得到响应之前function我的事件从它出来,然后从register函数返回到页面,由于该页面,{message}值在html页面中保持空白,尽管在后端firebas
firebase.auth().createUserWithEmailAndPassword
运行,但在我从firebase.auth().createUserWithEmailAndPassword($scope.user.email,$scope.user.password)得到响应之前
function我的事件从它出来,然后从register函数返回到页面,由于该页面,{message}
值在html页面中保持空白,尽管在后端firebase.auth().createUserWithEmailAndPassword($scope.user.email,$scope.user.password)
函数处理并获取响应,但事件在处理完成之前返回页面。我希望函数事件应该等到我得到响应
请注意,我使用的是firebase 3.x.x.firebase.auth()。createUserWithEmailAndPassword
是一个异步函数,它不是Angular.js的一部分。因此,Angular.js无法意识到其对$scope
的回调所做的修改,并且不会更新页面。在回调完成后,尝试添加$scope.apply()
myApp.controller('RegistrationController', ['$scope',
function($scope) {
var auth = firebase.database().ref();
// console.log("auth::"+auth);
$scope.login = function() {
$scope.message = "Welcome " + $scope.user.email;
}; //login
$scope.register = function() {
console.log($scope.user.email);
console.log($scope.user.password);
console.log("jdxnx::" + auth);
firebase.auth().createUserWithEmailAndPassword($scope.user.email, $scope.user.password).then(function() {
$scope.message = "Hi" + $scope.user.email + " you have registered"
}).catch(function(error) {
$scope.message = error.message;
console.log($scope.message);
}); // //createUser
}; // register
}
]); // Controller
其他你可能感兴趣的东西:
- 看看这个项目,它会在Firebase操作后触发Angular.js
- 不推荐使用Angular.js和独立控制器以及
,这种方式已经很久没有使用了。您可能希望将控制器视为语法(Angular.js 1.3+)或更好的组件(Angular.js 1.5+)$scope
$scope
的回调所做的修改,并且不会更新页面。在回调完成后,尝试添加$scope.apply()
myApp.controller('RegistrationController', ['$scope',
function($scope) {
var auth = firebase.database().ref();
// console.log("auth::"+auth);
$scope.login = function() {
$scope.message = "Welcome " + $scope.user.email;
}; //login
$scope.register = function() {
console.log($scope.user.email);
console.log($scope.user.password);
console.log("jdxnx::" + auth);
firebase.auth().createUserWithEmailAndPassword($scope.user.email, $scope.user.password).then(function() {
$scope.message = "Hi" + $scope.user.email + " you have registered"
}).catch(function(error) {
$scope.message = error.message;
console.log($scope.message);
}); // //createUser
}; // register
}
]); // Controller
其他你可能感兴趣的东西:
- 看看这个项目,它会在Firebase操作后触发Angular.js
- 不推荐使用Angular.js和独立控制器以及
,这种方式已经很久没有使用了。您可能希望将控制器视为语法(Angular.js 1.3+)或更好的组件(Angular.js 1.5+)$scope
$scope.$apply()
在“$scope.message=“Hi”+$scope.user.email+“您已注册”旁边,尝试添加$scope.$apply()
在“$scope.message=”Hi“+$scope.user.email+”您已注册“'谢谢Hugo,它正在工作,在代码中刚刚更正$scope。$apply()。谢谢Hugo,它正在工作,在代码中刚刚更正$scope。$apply()。