Tôi muốn đưa ra chỉ thị để mở một phương thức. Nhưng $ uibModal không được định nghĩa bên trong chỉ thị.
var app=angular.module("app",['ui.bootstrap']);
app.controller('AppCtrl', function ($scope, $uibModal) {
console.log("$uibModal controller",$uibModal);//getting object
});
app.directive('showPopUp',function() {
return {
restrict: 'EA',
link: function(scope, el, attrs,$uibModal) {
console.log("$uibModal",$uibModal);//undefined here
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: 'popup.html',
});
modalInstance.result.then(function (selectedItem) {
scope.selected = selectedItem;
}, function() {
});
}
}
});
Làm cách nào để sử dụng $ uibModal trong chỉ thị của tôi để mở phương thức?
Tôi nghĩ rằng bạn có thể thêm điều khiển để chỉ thị của bạn và bơm $ uibModal đó. Nó sẽ hoạt động tốt –