У меня проблема с моим кодом. Значение $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;
});
};
}]);
Любая помощь приветствуется.
благодаря
Вы можете обновить угловую $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