[英]Function inside angular controller not executing using ng-click
I have a modal that supposedly force logouts the user when he clicks the Ok. 我有一个模态,据说当用户单击“确定”时会强制注销该用户。 The problem is the function inside my ng-click
is not executing at all. 问题是我的ng-click
内部的功能根本没有执行。 Here's my codes 这是我的密码
Modal HTML: 模态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>
CONTROLLER: 控制器:
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 that calls the modal: 调用模式的函数:
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;
}
}
});
};
Anyone knows what's the problem with my code? 有人知道我的代码有什么问题吗?
Edit: There's no error coming from the dev console as well so i'm really confused. 编辑:从开发控制台也没有错误,所以我真的很困惑。 NOTE: forceLogOutUser()
is the function that calls the modal while forceLogOutUserOK()
is the function inside my controller. 注意: forceLogOutUser()
是调用模式的函数,而forceLogOutUserOK()
是控制器内部的函数。 Theyre not the same 他们不一样
$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;
}
}
});
}
On ng-click, call cancel() 在ng-click上,调用cancel()
In controller, pass $modalInstance to your controller 在控制器中,将$ modalInstance传递给控制器
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.