I want to show a modal box asking the user if they want to delete a post or not. I can't figure out how to pass the key which I pass in the key argument in which I also can alert.
I took the code from the angular twitterbootstrap site but I can't figure out a method to pass data to confirm the remove.
Thanks Mohammad
$scope.deletePost = function(key, post, event) {
alert(key);
var modalInstance = $modal.open({
templateUrl: 'deletePost.html',
controller: ModalInstanceCtrl,
resolve: {
items: function() {
return $scope.posts;
}
},
})
modalInstance.result.then(function(selectedItem) {
$scope.selected = selectedItem;
alert(selectedItem);
});
};
var ModalInstanceCtrl = function($scope, $modalInstance, items) {
$scope.items = items;
$scope.selected = {
item: $scope.items[0]
};
$scope.ok = function() {
$modalInstance.close($scope.selected.item);
};
$scope.cancel = function() {
$modalInstance.dismiss('cancel');
};
};
Send the key via resolve as a parameter (see plunker):
I would suggest using Bootstrap components written by the AngularUI Team. you can find a great set of Twitter Bootstrap components including Modal control.
Example:
html:
js:
Live example: http://plnkr.co/edit/xIjUONEVhY5lO2kLhV4f?p=preview