Angular Material and Jasmine : “ No provider for InjectionToken MdDialogData! ”

前端 未结 6 2032
醉梦人生
醉梦人生 2021-02-01 12:12

I have a component which is meant to be used in an Angular Material MdDialog :

@Component({
  ...
})
export class MyComponent {

  constructor(@Inject(MD_DIALOG_         


        
6条回答
  •  清歌不尽
    2021-02-01 12:31

    You can use Angular Optional decorator, I faced this problem before so

    if the component is not used as a popup try this snippet

    constructor(
      @Optional() public dialogRef: MatDialogRef,
      @Optional() @Inject(MAT_DIALOG_DATA) public data: any
    ) {}
    

提交回复
热议问题