In my Angular 15 application, when I hit the Save button, I need to close the dialog. The dialog is only used in one location in the code...in the save event. So I can do it one of two ways:
@ViewChild
for the dialog in the TS file and access that in the save method.Is there an advantage of one vs. the other?
Both approaches are valid and can work, but each has its own advantages and disadvantages.
Approach 1: Adding a @ViewChild
for the dialog in the TS file and accessing it in the save method.
Advantages:
@ViewChild
reference in other methods in the same componentDisadvantages:
ViewChild
reference, which can add
complexity.Approach 2: Passing the dialog element to the save event handler from the HTML.
Advantages:
Disadvantages: