1
- import { NgModule , Component , ElementRef , OnInit , AfterViewInit , AfterViewChecked , DoCheck , OnDestroy , Input , Output , Renderer , EventEmitter , ContentChild , ViewChild , TemplateRef , IterableDiffers , forwardRef } from '@angular/core' ;
1
+ import { NgModule , Component , ElementRef , OnInit , AfterViewInit , AfterViewChecked , DoCheck , OnDestroy , Input , Output , Renderer , EventEmitter , ContentChildren , QueryList , ViewChild , TemplateRef , IterableDiffers , forwardRef } from '@angular/core' ;
2
2
import { CommonModule } from '@angular/common' ;
3
3
import { SelectItem } from '../common/api' ;
4
- import { SharedModule } from '../common/shared' ;
4
+ import { SharedModule , PrimeTemplate } from '../common/shared' ;
5
5
import { DomHandler } from '../dom/domhandler' ;
6
6
import { NG_VALUE_ACCESSOR , ControlValueAccessor } from '@angular/forms' ;
7
7
@@ -53,7 +53,7 @@ export const DROPDOWN_VALUE_ACCESSOR: any = {
53
53
` ,
54
54
providers : [ DomHandler , DROPDOWN_VALUE_ACCESSOR ]
55
55
} )
56
- export class Dropdown implements OnInit , AfterViewInit , AfterViewChecked , DoCheck , OnDestroy , ControlValueAccessor {
56
+ export class Dropdown implements OnInit , AfterViewInit , AfterContentInit , AfterViewChecked , DoCheck , OnDestroy , ControlValueAccessor {
57
57
58
58
@Input ( ) options : SelectItem [ ] ;
59
59
@@ -80,18 +80,16 @@ export class Dropdown implements OnInit,AfterViewInit,AfterViewChecked,DoCheck,O
80
80
@Output ( ) onFocus : EventEmitter < any > = new EventEmitter ( ) ;
81
81
82
82
@Output ( ) onBlur : EventEmitter < any > = new EventEmitter ( ) ;
83
-
84
- @ContentChild ( TemplateRef ) itemTemplate : TemplateRef < any > ;
85
-
83
+
86
84
@ViewChild ( 'container' ) containerViewChild : ElementRef ;
87
85
88
86
@ViewChild ( 'panel' ) panelViewChild : ElementRef ;
89
87
90
88
@ViewChild ( 'itemswrapper' ) itemsWrapperViewChild : ElementRef ;
91
-
92
- constructor ( public el : ElementRef , public domHandler : DomHandler , public renderer : Renderer , differs : IterableDiffers ) {
93
- this . differ = differs . find ( [ ] ) . create ( null ) ;
94
- }
89
+
90
+ @ ContentChildren ( PrimeTemplate ) templates : QueryList < any > ;
91
+
92
+ public itemTemplate : TemplateRef < any > ;
95
93
96
94
selectedOption : SelectItem ;
97
95
@@ -130,6 +128,24 @@ export class Dropdown implements OnInit,AfterViewInit,AfterViewChecked,DoCheck,O
130
128
public hoveredItem : any ;
131
129
132
130
public selectedOptionUpdated : boolean ;
131
+
132
+ constructor ( public el : ElementRef , public domHandler : DomHandler , public renderer : Renderer , differs : IterableDiffers ) {
133
+ this . differ = differs . find ( [ ] ) . create ( null ) ;
134
+ }
135
+
136
+ ngAfterContentInit ( ) {
137
+ this . templates . forEach ( ( item ) => {
138
+ switch ( item . getType ( ) ) {
139
+ case 'item' :
140
+ this . itemTemplate = item . template ;
141
+ break ;
142
+
143
+ default :
144
+ this . itemTemplate = item . template ;
145
+ break ;
146
+ }
147
+ } ) ;
148
+ }
133
149
134
150
ngOnInit ( ) {
135
151
this . optionsToDisplay = this . options ;
0 commit comments