-2

base class: since my ts file handling multiple feature's i am splitting them.

   constructor(
           
        ) {
            super(MatDialog);
        }

error: Argument of type 'typeof MatDialog' is not assignable to parameter of type 'MatDialog'.

super class:

export class AddClicnicComponent {
    popTableSchema;
    tableSchema;
    @ViewChild('popupTemp', { static: true })
    popupTemp: TemplateRef<HTMLAllCollection>;

    constructor(public dialog: MatDialog) {
        console.log('i am called by super');
    }
    handleAddClinic() {
        this.popTableSchema = { ...this.tableSchema };
        this.openDialog(this.popupTemp);
    }
    openDialog(templateRef: TemplateRef<HTMLAllCollection>) {
        const dialogRef = this.dialog.open(templateRef);
        dialogRef.afterClosed().subscribe((result) => {
            console.log(`Dialog result: ${result}`);
        });
    }
}

what is the exact params i need to send with super? can't i avoid the params? or what is the right way? needs the help.

3gwebtrain
  • 14,640
  • 25
  • 121
  • 247

2 Answers2

1

you should first add the MatDialog dependency to the constructor and then pass that instance to the super something like

constructor(public dialog: MatDialog) {
            super(dialog); //instance(i.e dialog) is passed here instead of type MatDialog
        }
jitender
  • 10,238
  • 1
  • 18
  • 44
  • It works. but need to construct in 2 place? can't it avoidable? – 3gwebtrain Nov 11 '22 at 07:29
  • @3gwebtrain if you are inheriting and want to pass dependency to the constructor than you will have to do it this way or you can get the dependency directly see following question https://stackoverflow.com/questions/37482460/getting-instance-of-service-without-constructor-injection – jitender Nov 11 '22 at 07:32
0

You are sending the class definition to the parent class but you need to send the class istance.

Dragan Petrovic
  • 201
  • 1
  • 5