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

依然范特西╮ 提交于 2019-12-24 17:06:47

问题


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:


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.



来源:https://stackoverflow.com/questions/30742887/unknown-provider-modalinstanceprovider-modalinstance-in-angularjs-modal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!