$uibModalInstance.close 不起作用 [英] $uibModalInstance.close not working
本文介绍了$uibModalInstance.close 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
.service('loginModal', function($rootScope, $uibModal) {
function updateUserData(user, data) {
Object.keys(data).forEach(function(key) {
user.facebook[key] = data[key];
});
return user.$update();
}
return function() {
var instance = $uibModal.open({
templateUrl: 'tpls/modals/login.html',
controller: function($scope, $uibModalInstance, facebookService, UserService) {
function updateUserData(user, data) {
Object.keys(data).forEach(function(key) {
user.facebook[key] = data[key];
});
return user.$update();
}
$scope.login = function() {
facebookService.login().then(function(response) {
var authResponse = facebookService.getAuthResponse();
facebookService.api('/me').then(function(response) {
if (response && !response.error) {
response.picture = 'http://graph.facebook.com/' + response.id + '/picture?type=large';
UserService.query({
'facebook.id': response.id,
'facebook.token': authResponse.accessToken
}).$promise.then(function(results) {
response.token = {
value: authResponse.accessToken,
expiresIn: authResponse.expiresIn
};
if (results.length > 0)
updateUserData(results[0], response) //THIS DOES NOT FULFILL OR REJECT
.then($uibModalInstance.close, $uibModalInstance.dismiss);
else
UserService.save({
facebook: response,
local: {
username: response.email || response.id,
password: response.token.value
}
}).$promise
.then($uibModalInstance.close, $uibModalInstance.dismiss);
}, $uibModalInstance.dismiss);
} else {
$uibModalInstance.dismiss(response.error || response);
}
}, $uibModalInstance.dismiss);
}, $uibModalInstance.dismiss);
};
}
instance.opened.then(function() {
$rootScope.openModals.push(instance);
});
function removeInstanceFromModalList() {
$rootScope.openModals.splice($rootScope.openModals.indexOf(instance), 1);
}
instance.result.then(removeInstanceFromModalList, removeInstanceFromModalList);
return instance.result;
}
基本上我从我想要的任何地方调用 loginModal().then(function(user){...},function(e){...});
.
Basically I'm calling loginModal().then(function(user){...},function(e){...});
from wherever I want.
但是在我查询UserService
if (results.length > 0)
updateUserData(results[0], response) //THIS DOES NOT FULFILL OR REJECT
.then($uibModalInstance.close, $uibModalInstance.dismiss);
我也试过这样调试:
updateUserData(results[0], response)
.then(function(usr) {
$uibModalInstance.close(usr); //debugger reaches this statement,
//nothing happens
}, function(e) {
$uibModalInstance.dismiss(e);
});
我的代码有什么问题?似乎只有背景点击才能关闭对话框.
What's wrong with my code? only backdrop clicks seem to close the dialog.
推荐答案
Dangit - 存在版本问题.
Dangit - had a version issue.
显然我使用的 angular-ui 版本与 angular#1.4.7 不兼容,所以我不得不升级到 1.4.8.
Apperantly the version of angular-ui I was using was incompatible with angular#1.4.7 so I had to upgrade to 1.4.8.
这篇关于$uibModalInstance.close 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文