未知提供者:$modalInstanceProvider <- Angularjs modal 中的 $modalInstance [英] Unknown provider: $modalInstanceProvider <- $modalInstance in Angularjs modal
问题描述
我正在使用 angular bootstrap ui modal,它工作正常,但是当我尝试使用 modalInstance 关闭它时,它给出了上述错误.这是我的代码
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');
};
}]);
我在我用模板指定的控制器中创建了取消函数,但它仍然给出错误.我在 LoginController 内的按钮中使用 ng-click="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?
推荐答案
看起来您正在模态视图中使用 ng-controller 指令实例化控制器.相反,您只需要使用模态的 controller
选项即可注入特殊的依赖项 $modalInstance
.如果您使用 ng-controller="LoginController"
实例化了控制器,则需要将其删除,并且不需要它,因为控制器会自动实例化(通过解析特殊依赖项 $modalInstance
) 并附加到模板.
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.
这篇关于未知提供者:$modalInstanceProvider <- Angularjs modal 中的 $modalInstance的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!