How to add click event on mat-row in angular material table

后端 未结 5 690
时光说笑
时光说笑 2020-12-28 14:23

I added this but when inspecting element using Chrome DevTools, the click function doesn\'t show!

Here\'s my code:



        
5条回答
  •  长发绾君心
    2020-12-28 14:43

    I would prefer to add a formControl to the material table as such

    
           ....
    
    

    and then in my ngOnInit method use

    readonly formControl = new FormControl();
    
    ngOnInit(): void {
        this.formControl.valueChanges.subscribe((request: RequestViewModel) => {
          this.selectedInvestigationId(request.investigation.investigationInfoId, request.speciality);
        });
      }
    

    The benefits are numerous:

    • It will work with keyboard navigation (formControl treats selection with SPACE/ENTER/click equally).
    • It can use form validation
    • You can use form flags, such as ng-dirty

提交回复
热议问题