从内部关闭 $uibModal
Dismiss $uibModal from within
我正在使用 Bootstrap 的 $uibModal 在我的网络应用程序中制作表格。一切正常,除了对话框显示后无法关闭。
我花了两天时间尽量不 post 回答这么简单的问题,尤其是当我收到的同一个错误有很多答案时,即
"Unknown provider: $uibModalInstanceProvider <- $uibModalInstance <-
ModalInstanceCtrl".
为了在操作大型应用程序时更加轻松,我将代码分成了单独的文件,并且在 html 中使用了 'controller as' 样式,因此代码中没有 $scopes。
无论我做什么,我都会不断收到我之前提到的这个错误。
我需要的是在用户成功登录后关闭对话框。
index.html:
...
<script src="rf/angular.min.js"></script>
<script src="rf/angular-animate.js"></script>
<script src="rf/angular-touch.js"></script>
<script src="rf/ui-bootstrap-tpls.js"></script>
<!-- Project files -->
<script src="application.js" type="text/javascript"></script>
<script src="frmLogin.js"></script>
</head>
<body>
<!-- Load things into this division -->
<div ng-include src="loaderCtrl.cFragment" ng-app="dgis" ng-controller="applicationController as loaderCtrl"></div>
</body>
application.js
var myApp = angular
.module('dgis', ['ui.bootstrap'])
.controller("applicationController", ['$http', '_gl', '$uibModal', function ($http, _gl, $uibModal) {
_gl.AppReference = this;
// Enable animations
this.animationsEnabled = true;
// Declare modal window
this.showFrmLogin = function (size) {
var modalInstance = $uibModal.open({
animation: this.animationsEnabled,
templateUrl: 'frmLogin.html',
controller: 'ModalInstanceCtrl',
size: size,
backdrop: 'static',
keyboard: false,
resolve: {
items: function () {
return this.items;
}
}
});
};
this.showFrmLogin();
frmLogin.js
myApp.controller('ModalInstanceCtrl', ['_gl', '$uibModalInstance', function (_gl, $uibModalInstance) {
this.login = function () {
angular.forEach(some_array, function (element) {
if (something == element)
// This code executes successfully and shows the page
_gl.AppReference.cFragment = "frmMain.html";
// This line does not close the dialog
$uibModalInstance.close('a');
}
});
}
}]);
和_gl - 是我用来保存全局变量的服务
使用 $rootScope
初始化模态时使用 $rootScope.modalInstance
然后您可以从应用程序的任何地方访问它。
希望这有帮助
- 删除 $uibModalInstance 引用
而不是"var modalInstance = $uibModal.open({"
使用“$rootScope.modalInstance = $uibModal.open({
而不是 $uibModalInstance.close('a');"
使用“$rootScope.modalInstance.close('a');”
我正在使用 Bootstrap 的 $uibModal 在我的网络应用程序中制作表格。一切正常,除了对话框显示后无法关闭。
我花了两天时间尽量不 post 回答这么简单的问题,尤其是当我收到的同一个错误有很多答案时,即
"Unknown provider: $uibModalInstanceProvider <- $uibModalInstance <- ModalInstanceCtrl".
为了在操作大型应用程序时更加轻松,我将代码分成了单独的文件,并且在 html 中使用了 'controller as' 样式,因此代码中没有 $scopes。
无论我做什么,我都会不断收到我之前提到的这个错误。 我需要的是在用户成功登录后关闭对话框。
index.html:
...
<script src="rf/angular.min.js"></script>
<script src="rf/angular-animate.js"></script>
<script src="rf/angular-touch.js"></script>
<script src="rf/ui-bootstrap-tpls.js"></script>
<!-- Project files -->
<script src="application.js" type="text/javascript"></script>
<script src="frmLogin.js"></script>
</head>
<body>
<!-- Load things into this division -->
<div ng-include src="loaderCtrl.cFragment" ng-app="dgis" ng-controller="applicationController as loaderCtrl"></div>
</body>
application.js
var myApp = angular
.module('dgis', ['ui.bootstrap'])
.controller("applicationController", ['$http', '_gl', '$uibModal', function ($http, _gl, $uibModal) {
_gl.AppReference = this;
// Enable animations
this.animationsEnabled = true;
// Declare modal window
this.showFrmLogin = function (size) {
var modalInstance = $uibModal.open({
animation: this.animationsEnabled,
templateUrl: 'frmLogin.html',
controller: 'ModalInstanceCtrl',
size: size,
backdrop: 'static',
keyboard: false,
resolve: {
items: function () {
return this.items;
}
}
});
};
this.showFrmLogin();
frmLogin.js
myApp.controller('ModalInstanceCtrl', ['_gl', '$uibModalInstance', function (_gl, $uibModalInstance) {
this.login = function () {
angular.forEach(some_array, function (element) {
if (something == element)
// This code executes successfully and shows the page
_gl.AppReference.cFragment = "frmMain.html";
// This line does not close the dialog
$uibModalInstance.close('a');
}
});
}
}]);
和_gl - 是我用来保存全局变量的服务
使用 $rootScope
初始化模态时使用 $rootScope.modalInstance
然后您可以从应用程序的任何地方访问它。 希望这有帮助
- 删除 $uibModalInstance 引用
而不是"var modalInstance = $uibModal.open({"
使用“$rootScope.modalInstance = $uibModal.open({
而不是 $uibModalInstance.close('a');"
使用“$rootScope.modalInstance.close('a');”