How can I programmatically trigger ripple effect on Angular MatListItem?

后端 未结 2 1461
囚心锁ツ
囚心锁ツ 2021-01-21 14:21

In Angular material you have the lovely ripple effect on a lot of the components. When you click on a mat-list-item the ripple effect happens.

Now with buttons and many

2条回答
  •  醉梦人生
    2021-01-21 15:06

    You can try dynamic template reference variable. It works to me.

    import { MatRipple } from '@angular/material/core';
    
    export class FooComponent {
        @ViewChildren(MatRipple) rippleList: QueryList;
    
        ngAfterViewInit() {
            let ripples = this.rippleList.toArray()
            ripples.forEach(res => {
                    // res is the instance of each matRipple
            })
        }
    
    }
    
    
    

    But It confused to me that I can use it perfect in my project but I can't reappear it in stackblitz:(

提交回复
热议问题