Unknown provider: $modalInstanceProvider <- $mo

2019-08-15 02:55发布

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条回答
Luminary・发光体
2楼-- · 2019-08-15 03:51

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.

查看更多
登录 后发表回答