1- import { AfterViewInit , Directive , ElementRef , Input , OnDestroy } from '@angular/core' ;
1+ import { AfterViewInit , Directive , ElementRef , Input , OnChanges , OnDestroy , SimpleChanges } from '@angular/core' ;
22import { coerceBooleanProperty } from '@angular/cdk/coercion' ;
33import { supportsPassiveEventListeners } from '@angular/cdk/platform' ;
44
@@ -10,7 +10,7 @@ import {MDCRippleFoundation, MDCRippleAdapter} from '@material/ripple';
1010 selector : '[mdcRipple], mdc-ripple' ,
1111 providers : [ MdcRipple ] ,
1212} )
13- export class MdcRippleDirective implements AfterViewInit , OnDestroy , MDCRippleCapableSurface {
13+ export class MdcRippleDirective implements AfterViewInit , OnChanges , OnDestroy , MDCRippleCapableSurface {
1414 _root ! : Element ;
1515
1616 @Input ( )
@@ -29,11 +29,6 @@ export class MdcRippleDirective implements AfterViewInit, OnDestroy, MDCRippleCa
2929 }
3030 set primary ( value : boolean ) {
3131 this . _primary = coerceBooleanProperty ( value ) ;
32- if ( this . _primary ) {
33- this . attachTo . classList . add ( 'mdc-ripple-surface--primary' ) ;
34- } else {
35- this . attachTo . classList . remove ( 'mdc-ripple-surface--primary' ) ;
36- }
3732 }
3833 private _primary = false ;
3934
@@ -43,11 +38,6 @@ export class MdcRippleDirective implements AfterViewInit, OnDestroy, MDCRippleCa
4338 }
4439 set secondary ( value : boolean ) {
4540 this . _secondary = coerceBooleanProperty ( value ) ;
46- if ( this . _secondary ) {
47- this . attachTo . classList . add ( 'mdc-ripple-surface--accent' ) ;
48- } else {
49- this . attachTo . classList . remove ( 'mdc-ripple-surface--accent' ) ;
50- }
5141 }
5242 private _secondary = false ;
5343
@@ -76,6 +66,24 @@ export class MdcRippleDirective implements AfterViewInit, OnDestroy, MDCRippleCa
7666 this . _ripple = this . _createRipple ( ) ;
7767 }
7868
69+ ngOnChanges ( changes : SimpleChanges ) {
70+ if ( changes [ 'primary' ] && this . attachTo ) {
71+ if ( this . _primary ) {
72+ this . attachTo . classList . add ( 'mdc-ripple-surface--primary' ) ;
73+ } else {
74+ this . attachTo . classList . remove ( 'mdc-ripple-surface--primary' ) ;
75+ }
76+ }
77+
78+ if ( changes [ 'secondary' ] && this . attachTo ) {
79+ if ( this . _secondary ) {
80+ this . attachTo . classList . add ( 'mdc-ripple-surface--accent' ) ;
81+ } else {
82+ this . attachTo . classList . remove ( 'mdc-ripple-surface--accent' ) ;
83+ }
84+ }
85+ }
86+
7987 ngAfterViewInit ( ) : void {
8088 this . _ripple . init ( ) ;
8189 }
0 commit comments