@@ -13,7 +13,7 @@ import {
13
13
QueryList ,
14
14
ViewEncapsulation
15
15
} from '@angular/core' ;
16
- import { defer , merge , Observable , Subject } from 'rxjs' ;
16
+ import { defer , merge , Observable , Subject , Subscription } from 'rxjs' ;
17
17
import { startWith , switchMap , take , takeUntil } from 'rxjs/operators' ;
18
18
19
19
import { toBoolean , EventRegistry } from '@angular-mdc/web/common' ;
@@ -38,6 +38,9 @@ export class MdcChipSet implements AfterContentInit, OnInit, OnDestroy {
38
38
/** Emits whenever the component is destroyed. */
39
39
private _destroy = new Subject < void > ( ) ;
40
40
41
+ /** Subscription to remove changes in chips. */
42
+ private _chipRemoveSubscription : Subscription | null ;
43
+
41
44
/**
42
45
* Indicates that the chips in the set are choice chips, which allow a single selection from a set of options.
43
46
*/
@@ -81,6 +84,11 @@ export class MdcChipSet implements AfterContentInit, OnInit, OnDestroy {
81
84
82
85
@ContentChildren ( MdcChip ) chips : QueryList < MdcChip > ;
83
86
87
+ /** Combined stream of all of the child chips' remove change events. */
88
+ get chipRemoveChanges ( ) : Observable < MdcChipInteractionEvent > {
89
+ return merge ( ...this . chips . map ( chip => chip . removed ) ) ;
90
+ }
91
+
84
92
/** Combined stream of all of the chip change events. */
85
93
readonly chipSelectionChanges : Observable < MdcChipInteractionEvent > = defer ( ( ) => {
86
94
if ( this . chips ) {
@@ -122,6 +130,10 @@ export class MdcChipSet implements AfterContentInit, OnInit, OnDestroy {
122
130
this . _foundation . handleChipInteraction ( event ) ;
123
131
} ) ;
124
132
133
+ this . _chipRemoveSubscription = this . chipRemoveChanges . subscribe ( ( event : MdcChipInteractionEvent ) => {
134
+ this . _foundation . handleChipRemoval ( event ) ;
135
+ } ) ;
136
+
125
137
this . chips . changes . pipe ( startWith ( null ) , takeUntil ( this . _destroy ) ) . subscribe ( ( ) => {
126
138
Promise . resolve ( ) . then ( ( ) => {
127
139
this . chips . forEach ( chip => {
0 commit comments