本文介绍了$ uibModalInstance.close不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的code:

\r
\r

。服务('loginModal',函数($ rootScope,$ uibModal){\r
      功能updateUserData(用户数据){\r
        Object.keys(数据).forEach(功能(键){\r
          user.facebook [关键] =数据[关键]\r
        });\r
        返回用户$ update()方法。\r
\r
      }\r
\r
      返回功能(){\r
          例如VAR = $ uibModal.open({\r
                templateUrl:第三方物流企业/情态动词/ login.html的,\r
                控制器:函数($范围,$ uibModalInstance,facebookService,UserService){\r
                  功能updateUserData(用户数据){\r
                    Object.keys(数据).forEach(功能(键){\r
                      user.facebook [关键] =数据[关键]\r
                    });\r
                    返回用户$ update()方法。\r
                  }\r
\r
                  $ scope.login =功能(){\r
                    facebookService.login()。然后(功能(响应){\r
                      变种authResponse = facebookService.getAuthResponse();\r
                      facebookService.api('/我),然后(功能(响应){\r
                        如果(响应和放大器;&安培;!response.error){\r
                          response.picture ='http://graph.facebook.com/'+ response.id +'?/图像类型=大';\r
                          UserService.query({\r
                            facebook.id':response.id,\r
                            facebook.token':authResponse.accessToken\r
                          })$。promise.then(功能(结果){\r
                            response.token = {\r
                              值:authResponse.accessToken,\r
                              expiresIn:authResponse.expiresIn\r
                            };\r
                            如果(results.length大于0)\r
                              updateUserData(结果[0],响应)//这不履行或拒绝\r
                              。然后($ uibModalInstance.close,$ uibModalInstance.dismiss);\r
                            其他\r
                              UserService.save({\r
                                Facebook的:响应,\r
                                本地:{\r
                                  用户名:response.email || response.id,\r
                                  密码:response.token.value\r
                                }\r
                              })$承诺\r
                              。然后($ uibModalInstance.close,$ uibModalInstance.dismiss);\r
                          } $ uibModalInstance.dismiss);\r
                        }其他{\r
                          $ uibModalInstance.dismiss(response.error ||响应);\r
                        }\r
                      } $ uibModalInstance.dismiss);\r
                    } $ uibModalInstance.dismiss);\r
                  };\r
                }\r
\r
                  instance.opened.then(函数(){\r
                  $ rootScope.openModals.push(实例);\r
                });\r
\r
                功能removeInstanceFromModalList(){\r
                  $ rootScope.openModals.splice($ rootScope.openModals.indexOf(实例),1);\r
                }\r
\r
                instance.result.then(removeInstanceFromModalList,removeInstanceFromModalList);\r
                返回instance.result;\r
              }

\r

\r
\r

基本上我打电话 loginModal(),然后(功能(用户){...},功能(E){...}); 随时随地我想要的。

不工作,但部分是我查询后立即 UserService

\r
\r

如果(results.length大于0)\r
  updateUserData(结果[0],响应)//这不履行或拒绝\r
  。然后($ uibModalInstance.close,$ uibModalInstance.dismiss);

\r

\r
\r

我也试过这样的调试:

\r
\r

updateUserData(结果[0],响应)\r
  。然后(功能(USR){\r
    $ uibModalInstance.close(USR); //调试器到达这一说法,\r
                                  //什么都没发生\r
  },功能(E){\r
    $ uibModalInstance.dismiss(E);\r
  });

\r

\r
\r

这有什么错我的code?只有点击背景似乎关闭对话框。


解决方案

Dangit - 有一个版本的问题,

Apperantly的,我采用了棱角分明的UI的版本是具有角#1.4.7不兼容,所以我不得不升级到1.4.8。

I have the following code:

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

Basically I'm calling loginModal().then(function(user){...},function(e){...}); from wherever I want.

The part which does not work however is right after I query UserService

if (results.length > 0)
  updateUserData(results[0], response) //THIS DOES NOT FULFILL OR REJECT
  .then($uibModalInstance.close, $uibModalInstance.dismiss);

I've also tried debugging like this:

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 - had a version issue.

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不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 03:35