我试图在页面上显示$ mdDialog以确认删除对象。我在页面上有一个简单的删除按钮,连接到控制器功能:
<button ng-click="delete(item, $event)">Delete</button>
在控制器中,我有:
$scope.delete = function (item, ev) {
var confirm = $mdDialog.confirm()
.title('Delete item?')
.textContent('The item will be irretrievably deleted!')
.ariaLabel('Delete')
.targetEvent(ev)
.ok('Delete!')
.cancel('Cancel');
$mdDialog.show(confirm).then(function () {
// delete
console.log("test");
}, function () {
// don't delete
});
};
我无法弄清楚如何将item
对象传递给实际的删除函数。 documentation显示了如何将locals传递到对话框中,但这似乎排除了使用confirm()
来构建选项。
提供从
$mdDialogPreset
返回的alert()
,以及confirm()
,或具有以下属性的选项对象:
(强调我的)
答案 0 :(得分:1)
您应该只能使用'item'。
$scope.delete = function (item, ev) {
var confirm = $mdDialog.confirm()
.title('Delete item?')
.textContent('The item will be irretrievably deleted!')
.ariaLabel('Delete')
.targetEvent(ev)
.ok('Delete!')
.cancel('Cancel');
$mdDialog.show(confirm).then(function () {
//item is available here
console.log(item);
}, function () {
// don't delete
});
};