我想使用的角度ui.bootstrap
實現像this一些功能,但是這顯示了一個錯誤
[$注射器:unpr] http://errors.angularjs.org/1.5.2/ $噴射器/ unpr?P0 =%24modalProvider%20%3 C-%20%24modal%20%3 C-%20ngReallyClickDirective
我的代碼是
app.js個
var app = angular.module('app',['ui.router','oc.lazyLoad','ui.bootstrap','ngReallyClickModule']);
ngReallyClickModule.js
angular.module('ngReallyClickModule',['ui.router'])
.directive('ngReallyClick', ['$modal',
function($modal) {
var ModalInstanceCtrl = function($scope, $modalInstance) {
$scope.ok = function() {
$modalInstance.close();
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
};
return {
restrict: 'A',
scope:{
ngReallyClick:"&",
item:"="
},
link: function(scope, element, attrs) {
element.bind('click', function() {
var message = attrs.ngReallyMessage || "Are you sure ?";
var modalHtml = '<div class="modal-body">' + message + '</div>';
modalHtml += '<div class="modal-footer"><button class="btn btn-primary" ng-click="ok()">OK</button><button class="btn btn-warning" ng-click="cancel()">Cancel</button></div>';
var modalInstance = $modal.open({
template: modalHtml,
controller: ModalInstanceCtrl
});
modalInstance.result.then(function() {
scope.ngReallyClick({item:scope.item});
}, function() {
//Modal dismissed
});
});
}
}
}
]);
查看
<a ng-really-message="Are you sure ?" ng-really-click="test(item)" item="item" ng-repeat="item in [1,2,3,4,5]">Delete</a>
我要上ng-really-click
點擊模態對話框。點擊模式確定按鈕,調用當前控制器的功能。
我使用angular-ui-router
和oclazyLoading
假設適度最新版本,它是'$ uibModal'和'$ uibModalInstance'〜https://angular-ui.github.io/bootstrap/#/modal – Phil