2

我正在尝试 angular 2 的 kendo ui,并且关闭、单击事件似乎在 kendo 对话框上起作用。但是有没有打开和关闭对话框的方法,或者我必须使用 javascript 吗?

4

1 回答 1

5

这里的简单示例:http: //plnkr.co/edit/Sm1T3rXkHNb04waFkkzG ?p=preview

只需使用一个简单的ngIf指令来控制窗口的打开/关闭状态。

import { Component } from '@angular/core';

@Component({
    selector: 'my-app',
    template: `
    <button (click)="dialogOpen = true">Open Dialog</button>
        <p>Status: {{ status }}</p>

        <kendo-dialog title="Action required" (close)="onDecline()" *ngIf="dialogOpen">
            <p>Do you accept?</p>

            <kendo-dialog-actions>
                <button kendoButton (click)="onAccept()">Yes</button>
                <button kendoButton (click)="onDecline()">No</button>
            </kendo-dialog-actions>
        </kendo-dialog>
    `
})
export class AppComponent {
    public status = "not open";
    dialogOpen : boolean = false;

    public onAccept() { this.status = "accepted"; this.closeDialog(); }
    public onDecline() { this.status = "declined"; this.closeDialog(); }

    private closeDialog() {
      this.dialogOpen = false;
    }
}
于 2016-11-03T07:24:36.290 回答