gpt4 book ai didi

javascript - AngularJS 错误 : $injector:unpr Unknown Provider - $modalInstanceProvider

转载 作者:行者123 更新时间:2023-11-29 19:13:54 33 4
gpt4 key购买 nike

我有一个按钮,您可以单击它,它应该会打开模式 onclick。但是,当我单击该按钮时,我收到错误消息“Unknown provider: $modalInstanceProvider <- $modalInstance”。到目前为止我检查了一切。我错过了什么?这是到目前为止的代码。

应用程序。 js - 加载 ui-bootstrap。

var app = angular.module('myApp', ['ngRoute', 'ui.bootstrap']);

services.js - 这是模态服务。

app.factory('modalService',['$uibModal', function($uibModal){
return {
openMenuModal: function(index, title, description) {
var modalObj = $uibModal.open({
templateUrl: 'partials/modal.html',
backdrop: 'static',
keyboard: true,
size: 'sm',
controller: function($scope, $modalInstance){
$scope.title = title;
$scope.description = description;

$scope.ok = function(id){
$modalInstance.close();
}
$scope.cancel = function(){
$modalInstance.dismiss('cancel');
}
}
});
}
};
}]);

家庭 Controller

app.controller('home', [
'$scope',
'contentService',
'$http',
'$uibModal',
'modalService', function($scope, contentService, $http, $uibModal, modalService){

contentService.then(function(data){
$scope.data = data;
$scope.shortcutList = $scope.data.shortcuts; // list of shortcuts
$scope.name = $scope.data.user; // user's name
$scope.userThumb = $scope.data.userThumb; // user thumbnail image


$scope.deleteBox = function(index, title, description){
modalService.openMenuModal('t', title, description);
};
});

}]);

模态模板

<div ng-controller="Home">
<div class="modalBox animated fadeIn">
<h1> {{title}} </h1>
<p>{{description}}</p>
<div class="modal-footer"></div>
</div>
</div>

快捷方式模板按钮 - 这是我要调用 deleteBox() 的地方

<button class="btn btn-primary deleteBox" ng-click="deleteBox($index,  'Are You sure you want to delete this?', 'description text')"></button>

最佳答案

使用 $uibModalInstance 而不是 $modalInstance

关于javascript - AngularJS 错误 : $injector:unpr Unknown Provider - $modalInstanceProvider,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36751962/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com