我的代码出了问题。在$scope
之后,$createUserWithEmailAndPassword
值未更新。但如果我发出警报($scope.message
),我可以看到警报。我哪里错了?
我正在使用来自firebase和Angularfire的所有更新文件。
我的app.js
` var spaapp = angular.module('spaapp',['ngRoute','firebase']);
spaapp.config(['$routeProvider', function ($routeProvider) {
$routeProvider.
when('/login', {
templateUrl: 'login.html',
controller: 'spaController'
}).
when('/register', {
templateUrl: 'register.html',
controller: 'spaController'
}).
when('/success', {
templateUrl: 'success.html',
controller: 'spaController'
}).
otherwise({
redirectTo: '/Main'
});
}]);
” 我的控制器
spaapp.factory("Auth", ["$firebaseAuth",
function($firebaseAuth) {
return $firebaseAuth();
}
]);
spaapp.controller('spaController', ['$scope','$rootScope', 'Auth',function ($scope,$rootScope,Auth) {
// $scope.authObj=firebaseAuth();
//var auth = Auth;
$scope.login = function () {
}
$scope.register = function () {
var email = $scope.user.email;
var password = $scope.user.password;
Auth.$createUserWithEmailAndPassword(email, password).then(function(regUser){
$scope.message="Hi" + regUser.uid;
console.log("Signed in as:" + regUser.uid );
}).catch(
function(error) {
var errorCode = error.code;
var errorMessage = error.message;
console.log(error.message);
$scope.message = error.message;
});
};
}]);
感谢任何帮助。
由于
答案 0 :(得分:1)
您可以通过调用$scope
上的$apply()
来刷新角度$scope
示例:
spaapp.factory("Auth", ["$firebaseAuth",
function($firebaseAuth) {
return $firebaseAuth();
}
]);
spaapp.controller('spaController', ['$scope','$rootScope', 'Auth',function ($scope,$rootScope,Auth) {
// $scope.authObj=firebaseAuth();
//var auth = Auth;
$scope.login = function () {
}
$scope.register = function () {
var email = $scope.user.email;
var password = $scope.user.password;
Auth.$createUserWithEmailAndPassword(email, password).then(function(regUser){
$scope.message="Hi" + regUser.uid;
console.log("Signed in as:" + regUser.uid );
}).catch(
function(error) {
var errorCode = error.code;
var errorMessage = error.message;
console.log(error.message);
$scope.message = error.message;
$scope.$apply() // HERE
});
};
}]);
更多关于角度消化循环的信息:
http://jimhoskins.com/2012/12/17/angularjs-and-apply.html