Close a window programmatically?

0 Answers 159 Views
Window
Clifford
Top achievements
Rank 1
Clifford asked on 21 Dec 2023, 05:08 PM

I am using the WindowService to open a window and passing in a template for the content. Once the user performs their action within the window, I want to close it.

I tried adding

public window : WindowRef

to my constructor, but this threw an error, 'No provider for WindowRef'

Georgi
Telerik team
commented on 26 Dec 2023, 10:14 AM

Hi Clifford,

Thank you very much for the details provided.

From what I understood from your question, you are currently utilizing the Kendo UI for Angular Window using the Angular Service and are looking for an approach that would allow you to programmatically close the component. Please, correct me if I misunderstood you.

Indeed, you are correct that the developer could use the WindowRef and the built-in close() method in order to close the Window component programmatically:

export class AppComponent {
    constructor(private windowService: WindowService) {}
    public windowRef: WindowRef;
    ...
    public showList(template: TemplateRef<unknown>): void {
        this.windowRef = this.windowService.open({
            title: 'My List',
            content: template,
            width: 250,
            height: 230,
        });
    }

    public onClick() {
        this.windowRef.close();
    }
}

To better illustrate the suggested approach, I am sending you a StackBlitz demo that implements it:

https://stackblitz.com/edit/angular-sjqdlb

I hope this helps. Please, let me know if I am missing out on something.

Regards,
Georgi
Progress Telerik
Clifford
Top achievements
Rank 1
commented on 27 Dec 2023, 04:28 PM

That did it. Thank you for the detailed answer!

No answers yet. Maybe you can help?

Tags
Window
Asked by
Clifford
Top achievements
Rank 1
Share this question
or