[英]Create Angular Modal Outside of Controller
In app.js
, and specifically within $rootScope.$on('$routeChangeStart')
I have a function that creates a modal: 在app.js
,尤其是在$rootScope.$on('$routeChangeStart')
我有一个创建模式的函数:
setIdleTimeout.$inject = ['$uibModal']
function setIdleTimeout(timerStart, timerDuration, $scope, $uibModal){
console.log('timerStart: ', timerStart, 'timerDuration: ', timerDuration)
setTimeout(function(){
console.log('setTimeout running')
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: '****',
controller: '****',
scope: $scope,
size: size,
backdrop : 'static',
resolve: {}
});
modalInstance.result.then(function (selectedItem) {
$scope.selected = selectedItem
}, function () { })
}, 10000)
}
Im getting Uncaught TypeError: Cannot read property 'open' of undefined
, even tho Im injecting it and including the source code in Index.html
Im Uncaught TypeError: Cannot read property 'open' of undefined
,即使我将其注入并在Index.html
包括源代码
<script src="~/lib/angular-bootstrap/ui-bootstrap-tpls.js"></script>
How do I create a modal outside of a controller? 如何在控制器外部创建模态?
Might need more detail about your code structure, specially the context where you call $rootScope.$on()... 可能需要更多有关代码结构的详细信息,尤其是调用$ rootScope。$ on()的上下文。
I think the problem you have here is $uibModal
is not properly injected. 我认为您在这里$uibModal
的问题是$uibModal
没有正确注入。 Instead of using $inject
in the setIdleTimeout
function, tried to inject the $uibModal
in the the same level as where you inject your $rootScope
. 不要在setIdleTimeout
函数中使用$inject
,而是尝试将$uibModal
注入与注入$rootScope
相同的级别。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.