Unknown provider: $modalInstanceProvider <- $modalInstance in Angularjs modal

6.4k views Asked by At

I am using angular bootstrap ui modal which is working fine but when I try to close it using modalInstance it gives above error.Here is my code

  var app = angular.module('LoginModule', ['ui.bootstrap']);
app.controller('LoginModal', ['$scope',  '$modal', function ($scope, $modal) {
    $scope.animationsEnabled = true;
    $scope.open = function (size) {

        var modalInstance = $modal.open({
            animation: $scope.animationsEnabled,
            templateUrl: '/app/template/Login.html',
            controller: 'LoginController',
            size: size
        });
    }
}]);
app.controller('LoginController', ['$scope', '$modalInstance', '$http', function ($scope, $modalInstance, $http) {
    $scope.model = {};
    $scope.loading = {
        state: false
    }
    $scope.errors = '';
    $scope.email = "";
    $scope.cancel = function () {

        $modalInstance.dismiss('cancel');
    };
}]);

I have created the cancel function in the controller which I specify with the template still it gives error.I use ng-click="cancel()" in button inside LoginController . Need help?

1

There are 1 answers

2
PSL On BEST ANSWER

Looks like you are instantiating the controller with ng-controller directive in the modal view. Instead you only need to use controller option of the modal in order to get the special dependency $modalInstance injected. If you have instantiated controller using ng-controller="LoginController" you need to remove it and you would not need it as well as the controller would automatically be instantiated (by resolving special dependency $modalInstance) and attached to the template.