Search code examples
angularjsangular-bootstrap

AngularJS Error: [$injector:unpr] Unknown provider:


I am getting an unknown provider error when attempting to launch an angular bootstrap modal window from my app by clicking on an image. I launch the same type of modal successfully elsewhere in the app.

Here is a screenshot of the error in the debugger

Is there something wrong with my controller code below? I looked at several other unknown provider error posts on stack, and to my knowledge I'm doing things properly.

app.controller('ModalInstanceCtrl', function($scope, $modalInstance, items,
 removeVideoFromCart, removeLiteratureFromCart, productHasItems, cartItemHasVideos,
 cartItemHasLiterature, getCartMailToBody, cartMailtoLink, logSentItems) {

    $scope.items = items;

    $scope.ok = function() {
        $modalInstance.close($scope.test);
    };

    $scope.removeVideoFromCart = function (video, familyIndex, index) {
        removeVideoFromCart(video, familyIndex, index);
        $scope.cartMailtoLink = getCartMailToBody(); //update the mailto link body to remove video links
    }

    $scope.removeLiteratureFromCart = function (literature, familyIndex, index) {
        removeLiteratureFromCart(literature, familyIndex, index); 
        $scope.cartMailtoLink = getCartMailToBody(); //update the mailto link body to remove lit links
    }       

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

    $scope.productHasItems = function(index) {
        return productHasItems(index);
    }

    $scope.cartItemHasVideos = function(index) {
        return cartItemHasVideos(index);
    }

    $scope.cartItemHasLiterature = function (index) {
        return cartItemHasLiterature(index);
    }

    $scope.getCartMailToBody = function () {
        getCartMailToBody();
    }
    $scope.cartMailtoLink = getCartMailToBody();

    $scope.logSentItems = function () {
        logSentItems();
    }

});

Thank you very much for your time. Let me know if you need more information or if I am being unclear.


Solution

  • @Claies @ritesh I was typing a long edit with responses to the questions when I happened upon my solution. I had multiple functions that opened modal windows using ModalInstanceController. For example, here are two:

    $scope.open = function(size) {
                    var modalInstance = $modal.open({
                        templateUrl: 'myModalContent.html',
                        controller: 'ModalInstanceCtrl',
                        size: size,
                        resolve: {
                            items: function() {
                                return $scope.selectedVideo3;
                            }
                        }
                    });
    
                    modalInstance.result.then(function(selectedItem) {
                        $scope.selected = selectedItem;
                    }, function() {
                        $log.info('Modal dismissed at: ' + new Date());
                    });
            };
    
            $scope.openCart = function(size) {
    
                var modalInstance = $modal.open({
                    templateUrl: 'myAttachmentModalContent.html',
                    controller: 'ModalInstanceCtrl',
                    size: size,
                    resolve: {
                        items: function() {
                            return "";
                       },
                        removeVideoFromCart: function() {
                                return $scope.removeVideoFromCart;
                        },
                        removeLiteratureFromCart: function() {
                                return $scope.removeLiteratureFromCart;
                        },
                        productHasItems: function() {
                                return $scope.productHasItems;
                        },
                        cartItemHasVideos: function() {
                            return $scope.cartItemHasVideos;
                        },
                        cartItemHasLiterature: function() {
                            return $scope.cartItemHasLiterature;
                        },
                        getCartMailToBody: function() {
                            return $scope.getCartMailToBody
                        },
                        cartMailtoLink: function() {
                            return $scope.cartMailtoLink
                        },
                        logSentItems: function () {
                            return $scope.logSentItems;
                        }
                    }
                });
    
                modalInstance.result.then(function(selectedItem) {
                    $scope.selected = selectedItem;
                }, function() {
                    $log.info('Modal dismissed at: ' + new Date());
                });
            };
    

    I only use most of the dependencies for ModalInstanceController in the openCart function, so I didn't add all of the dependency function declarations to my other open methods (You can see in the resolve for the $scope.open method above I only declare items and no functions).

    I needed to declare all of these functions like I did in $scope.openCart and it fixed my problem.

    Thank you for reaching out.