gpt4 book ai didi

javascript - $uibModalInstance.close 不工作

转载 作者:行者123 更新时间:2023-11-29 18:01:43 25 4
gpt4 key购买 nike

我有以下代码:

.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){...});

但不起作用的部分是在我查询 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);
});

我的代码有什么问题?似乎只有背景点击才能关闭对话框。

最佳答案

您可以使用 $uibModal.open() 返回的 promise ,它附加了 close() 方法。您可以将其存储在 Controller $scope 中:

$scope.modal_instance = $uibModal.open({ ...

然后使用:

$scope.modal_instance.close();

而不是 $uibModalInstance.close。

关于javascript - $uibModalInstance.close 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34487541/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com