简体   繁体   English

如何使用Angular和VMware Clarity的模态对话框?

[英]How to use modal dialog with Angular and VMware Clarity?

I need to display a modal dialog control with a question and yes/no buttons, wait for the user's choice, then run some code to perform the selected action. 我需要显示一个带有问题和是/否按钮的模态对话框控件,等待用户的选择,然后运行一些代码来执行所选的操作。

The VMWare Clarity documentation is very clear about the markup inside the dialog, but it does not talk about how to show or hide it. VMWare Clarity文档非常清楚对话框中的标记,但它没有讨论如何显示或隐藏它。

I'd love a complete example, thank you. 我想要一个完整的例子,谢谢。

I'm assuming you are describing a situation where you want to confirm an action (like confirm you wish to delete an item), and if so you should review the code found here. 我假设您正在描述要确认操作的情况(例如确认您要删除项目),如果是,您应该查看此处找到的代码。 You can follow the methods it calls to see the logic. 您可以按照它调用的方法来查看逻辑。

https://github.com/gnomeontherun/clarity-workshop/blob/master/src/app/budget/budget/budget.component.html#L56 https://github.com/gnomeontherun/clarity-workshop/blob/master/src/app/budget/budget/budget.component.html#L56

This is a delete button that calls a method, which then opens a modal dialog. 这是一个调用方法的删除按钮,然后打开一个模式对话框。 The user then confirms or cancels, and then if they confirm it calls the API to actually delete. 然后用户确认或取消,然后如果他们确认它调用API实际删除。

If you'd like to make your own service to control the modal, you can follow the example I have for an alert service and alert component (but change it to a modal). 如果您想要自己的服务来控制模态,您可以按照我的示例来获取警报服务和警报组件(但将其更改为模态)。 https://github.com/angular-in-action/portfolio/tree/master/src/app/alert https://github.com/angular-in-action/portfolio/tree/master/src/app/alert

Let's assume the user clicks on a "Delete order" button, and you want to display a modal dialog with "Are you sure?" 假设用户点击“删除订单”按钮,您想显示一个模式对话框,其中包含“您确定吗?” and "Cancel" and "Delete" buttons. 和“取消”和“删除”按钮。

Jeremy's example above is great. 杰里米上面的例子很棒。 Here is a minimal implementation: 这是一个最小的实现:

In order.component.ts : order.component.ts

isModalVisible = false;

deleteOrder() {
  ...
}

In order.component.html : order.component.html

<div>
  ...
  <button (click)="isModalVisible = true">Delete Order</button>
  ...
</div>

<clr-modal [(clrModalOpen)]="isModalVisible">
  <h3 class="modal-title">Delete order?</h3>
  <div class="modal-body">This cannot be undone.</div>
  <div class="modal-footer">
    <button type="button" class="btn (click)="isModalVisible = false">Cancel</button>
    <button type="button" class="btn (click)="deleteOrder()">Delete</button>
  </div>
</clr-modal>

Angular 6.1.9, Clarity 0.13.4 Angular 6.1.9,净度0.13.4

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM