未知提供者:$modalInstanceProvider <- Angularjs 模态中的 $modalInstance

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

我正在使用 angular bootstrap ui 模式,它工作正常但是当我尝试使用 modalInstance 关闭它时它给出上面 error.Here 是我的代码

  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');
    };
}]);

我已经在我用模板指定的控制器中创建了取消函数,它仍然提供 error.I 在 LoginController 中的按钮中使用 ng-click="cancel()" 。 需要帮助吗?

看起来您正在模态视图中使用 ng-controller 指令实例化控制器。相反,您只需要使用模态的 controller 选项即可获得注入的特殊依赖项 $modalInstance。如果您使用 ng-controller="LoginController" 实例化了控制器,则需要将其删除并且您不需要它,因为控制器将自动实例化(通过解析特殊依赖性 $modalInstance)并附加到模板。