9
9
IterableDiffers ,
10
10
Output ,
11
11
QueryList ,
12
- DoCheck
12
+ DoCheck ,
13
+ AfterViewInit
13
14
} from '@angular/core' ;
14
15
import {
15
16
IgxChipComponent ,
@@ -40,7 +41,7 @@ export interface IChipsAreaSelectEventArgs extends IBaseChipsAreaEventArgs {
40
41
selector : 'igx-chips-area' ,
41
42
templateUrl : 'chips-area.component.html' ,
42
43
} )
43
- export class IgxChipsAreaComponent implements DoCheck {
44
+ export class IgxChipsAreaComponent implements DoCheck , AfterViewInit {
44
45
45
46
/**
46
47
* @hidden
@@ -69,7 +70,7 @@ export class IgxChipsAreaComponent implements DoCheck {
69
70
public height : number ;
70
71
71
72
/**
72
- * Emits an event when `IgxChipComponent`s in the `IgxChipsAreaComponent` are reordered.
73
+ * Emits an event when `IgxChipComponent`s in the `IgxChipsAreaComponent` should be reordered.
73
74
* Returns an array of `IgxChipComponent`s.
74
75
* ```html
75
76
* <igx-chips-area #chipsArea [width]="'300'" [height]="'10'" (onReorder)="changedOrder($event)"></igx-chips-area>
@@ -84,7 +85,8 @@ export class IgxChipsAreaComponent implements DoCheck {
84
85
public onReorder = new EventEmitter < IChipsAreaReorderEventArgs > ( ) ;
85
86
86
87
/**
87
- * Emits an event when an `IgxChipComponent` in the `IgxChipsAreaComponent` is selected.
88
+ * Emits an event when an `IgxChipComponent` in the `IgxChipsAreaComponent` is selected/deselected.
89
+ * Fired after the chips area is initialized if there are initially selected chips as well.
88
90
* Returns an array of selected `IgxChipComponent`s and the `IgxChipAreaComponent`.
89
91
* ```html
90
92
* <igx-chips-area #chipsArea [width]="'300'" [height]="'10'" (onSelection)="selection($event)"></igx-chips-area>
@@ -145,6 +147,23 @@ export class IgxChipsAreaComponent implements DoCheck {
145
147
this . _differ = this . _iterableDiffers . find ( [ ] ) . create ( null ) ;
146
148
}
147
149
150
+ /**
151
+ * @hidden
152
+ */
153
+ public ngAfterViewInit ( ) {
154
+ // If we have initially selected chips through their inputs, we need to get them, because we cannot listen to their events yet.
155
+ if ( this . chipsList . length ) {
156
+ this . selectedChips = this . chipsList . filter ( ( item : IgxChipComponent ) => item . selected ) ;
157
+ if ( this . selectedChips . length ) {
158
+ this . onSelection . emit ( {
159
+ originalEvent : null ,
160
+ newSelection : this . selectedChips ,
161
+ owner : this
162
+ } ) ;
163
+ }
164
+ }
165
+ }
166
+
148
167
/**
149
168
* @hidden
150
169
*/
0 commit comments