我正在为Firebase电子邮件&密码登录制作UI Bootstrap模式窗口。模态窗口登录用户并返回authData
对象。模态窗口然后自行关闭。然后authData
对象不可用于主窗口或家庭控制器。
看来,模式窗口或其控制器正在制作一个孩子$scope
。 authData
对象可用于子$范围,但不在父$scope
上。
这里是home.html的按钮执行的代码,打开模态窗口:
<button type="button" class="btn btn-info" ng-click="openModal('md')">
E-mail & password</button>
这里是HomeController.js打开的模式窗口代码:
$scope.openModal = function(size) {
var modalInstance = $uibModal.open({
templateUrl: 'javascript/templates/emailLoginModalContent.html',
controller: 'EmailLoginModalInstanceCtrl',
scope: $scope,
size: size
});
};
请注意,我设置了scope: $scope
。我也试过scope: $parent
。
这里是模态窗口的控制器的一部分:
app.controller('EmailLoginModalInstanceCtrl', ['$scope', '$uibModalInstance', '$firebaseAuth', function($scope, $uibModalInstance, $firebaseAuth) {
console.log("EmailLoginModalInstanceCtrl controller.");
var ref = new Firebase("https://my-firebase.firebaseio.com/");
$scope.authObj = $firebaseAuth(ref);
// Login user
$scope.loginUser = function(user) {
ref.authWithPassword({
email: $scope.user.email,
password: $scope.user.password
}, function(error, authData) {
if (error) {
console.log("Login Failed!", error);
} else {
console.log("Authenticated successfully with payload:", authData);
$scope.authData = authData;
$scope.authData.uid = authData.uid;
console.log($scope.authData.uid);
$scope.reset();
$scope.cancel();
$scope.$apply(function() {
console.log("Applied!");
});
}
});
};
}]);
请注意,我试图$scope.authData = authData;
和$scope.authData.uid = authData.uid;
。都不能将authData
对象放在父$范围内。
我也尝试从家庭控制器运行$getAuth()
。得到了authData
对象并将其放在父项$scope
上。但是当模式窗口关闭时,我无法在Home Controller中获取代码。
有什么建议吗?
^这是方式。 您也可以传入模态实例的回调函数来访问$ uibModal中的变量作用域...这很好,通过添加解析。 var callingFn = function(){// do stuff}; VAR modalInstance = $ uibModal.open({ 大小:大小, templateUrl://..etc 决心:{passFn:callingFn} – razblack
正确答案:-)现在我明白了'''接近(结果) '''在文档中。谢谢! –