我对 UI Bootstrap 模式有疑问。
在一个 Controller 中我有这个:
app.controller("tableCtrl",['$scope','$http','$uibModal','$log' ,function ($scope, $http,$uibModal,$log) {
$scope.open = function (size,selectedUser) {
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'myModalContent.html',
controller:'ModalInstanceCtrl',
size: size,
resolve: {
user: function () {
return selectedUser;
}
}
});
}]);
在另一个我有这个:
app.controller('ModalInstanceCtrl',['$scope','$uibModalInstance','user', function ($scope, $uibModalInstance, user) {
$scope.user = user;
$scope.ok = function () {
$uibModalInstance.close();
};
}]);
myModalContent 看起来像这样:
<script type="text/ng-template" id="myModalContent.html">
<div class="modal-header"><h1>EDIT</h1></div>
<div class="modal-body">
{{patient.patient_id}}
</div>
<div class="modal-footer">
<button class="btn btn-primary" type="button" ng-click="ok()">OK</button>
</div>
</script>
我只在 HTML 中调用 tableCtrl 并像这样调用 open 函数:
<button class="btn btn-primary" ng-click="open('lg',patient)">Edit</button>
当我点击编辑按钮时,我收到了这个异常:
Unknown provider: $uibModalInstanceProvider <- $uibModalInstance
我看到了this plunker但这对我没有帮助。
怎么了?
最佳答案
我遇到了同样的问题,所以根据我的解决方案,这里是您如何解决您的场景
app.controller("tableCtrl",['$scope','$http','$uibModal','$log' ,function ($scope, $http,$uibModal,$log) {
$scope.open = function (size,selectedUser) {
var uibModalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'myModalContent.html',
controller:function($uibModalInstance ,$scope,user){
$scope.ok = function () {
$uibModalInstance.dismiss('cancel');
};
},
size: size,
resolve: {
user: function () {
return selectedUser;
}
}
});
}]);
关于javascript - 未知提供者 : $uibModalInstanceProvider - Bootstrap UI modal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33455271/