角度控制器内的功能不使用ng-click执行

时间:2017-09-13 09:23:06

标签: html angularjs

我有一个模式,据说当他点击Ok时强制注销用户。问题是我的ng-click内的函数根本没有执行。这是我的代码

模态HTML:

<!-- Modal content-->
<div class="col-md-12 col-xs-12">
   <div class="col-md-12 col-xs-12 text-left" style="margin-top: 40px;">
       <div>
          {{MessageHead}}
       </div>
    <div style="font-family: RobotoRegular; color: #7d7d7d;">
        {{MessageDetails}}
    </div>
    <div class="pull-right putCursor" ng-click="forceLogoutUserOK()"
         style="margin-top: 20px; margin-right: 15px;">
        OK
    </div>
  </div>
</div>

控制器:

app.controller('ExpiredSessionController', ['$scope', '$http', '$location', 'ErrorType', function($scope, $http, $location, ErrorType) {
   $scope.MessageHead = "Session Expired";
   $scope.MessageDetails = "Please login again.";

   console.log("Entered expired controllers");
   $scope.forceLogoutUserOK = function() {
       console.log("Clicked..");
       $scope.$modalInstanceForceLogout.dismiss('cancel');
       $location.path("/login");
   };

   switch (ErrorType) {
       case "EXPIRED":
           $scope.MessageHead = "Session Expired";
           $scope.MessageDetails = "Please login again.";
           break;
       case "INVALIDTIME":
           $scope.MessageHead = "Invalid Session";
           $scope.MessageDetails = "Please check your PC Date/Time.";
           break;
       default:
           $scope.MessageHead = "Something went wrong in your Session";
           $scope.MessageDetails = "Please login again.";
   };
}]);

调用模态的函数:

function forceLogOutUser($scope, $cookies, $http, $uibModal, errorType) {
     removeAllCookies($cookies);
     $scope.$modalInstanceForceLogout = $uibModal.open({
         scope: $scope,
         templateUrl: 'views/modals/expired-session.modal.html?v='+VERSION_NUMBER,
         controller: 'ExpiredSessionController',
         windowClass: 'expired-session-modal',
         backdrop: 'static',
         keyboard: false,
         resolve: {
             ErrorType: function () {
                 return errorType;
             }
         }
     });
 };

任何人都知道我的代码存在什么问题?

编辑:开发控制台也没有错误,所以我真的很困惑。 注意:forceLogOutUser()是调用模态的函数,而forceLogOutUserOK()是控制器内的函数。它们不一样

1 个答案:

答案 0 :(得分:0)

$scope.$modalInstanceForceLogout = function() {
     $uibModal.open({
         scope: $scope,
         templateUrl: 'views/modals/expired-session.modal.html?v='+VERSION_NUMBER,
         controller: 'ExpiredSessionController',
         windowClass: 'expired-session-modal',
         backdrop: 'static',
         keyboard: false,
         resolve: {
             ErrorType: function () {
                 return errorType;
             }
         }
     });
}

在ng-click上,调用cancel()

在控制器中,将$ modalInstance传递给控制器​​

$scope.cancel = function() {
    $modalInstance.dismiss('cancel');
};