0

In app.js, and specifically within $rootScope.$on('$routeChangeStart') I have a function that creates a modal:

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

<script src="~/lib/angular-bootstrap/ui-bootstrap-tpls.js"></script>

How do I create a modal outside of a controller?

1 Answer 1

1

Might need more detail about your code structure, specially the context where you call $rootScope.$on()...

I think the problem you have here is $uibModal is not properly injected. Instead of using $inject in the setIdleTimeout function, tried to inject the $uibModal in the the same level as where you inject your $rootScope.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.