15
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
16
*/
17
17
import { CommonModule } from '@angular/common' ;
18
- import { Component , NgModule , OnInit , Type } from '@angular/core' ;
18
+ import { ChangeDetectorRef , Component , inject , NgModule , OnInit , Type } from '@angular/core' ;
19
19
import { ReactiveFormsModule } from '@angular/forms' ;
20
20
import { FieldType , FormlyFieldConfig , FormlyModule } from '@ngx-formly/core' ;
21
21
import { FormlySelectModule as FormlyCoreSelectModule , FormlyFieldSelectProps } from '@ngx-formly/core/select' ;
@@ -54,8 +54,8 @@ export interface IFormlySelectFieldConfig extends FormlyFieldConfig<ISelectProps
54
54
@Component ( {
55
55
selector : 'ng-core-primeng-select' ,
56
56
template : `
57
- <div class="flex justify-content-center">
58
- <p-dropdown
57
+ @defer(when selectOptions) {
58
+ <p-dropdown
59
59
[appendTo]="props.appendTo"
60
60
[class]="props.class"
61
61
[dropdownIcon]="props.dropdownIcon"
@@ -90,7 +90,8 @@ export interface IFormlySelectFieldConfig extends FormlyFieldConfig<ISelectProps
90
90
<div class="option-group"><hr></div>
91
91
}
92
92
</ng-template>
93
- </p-dropdown>
93
+ </p-dropdown>
94
+ }
94
95
` ,
95
96
styles : `
96
97
:host ::ng-deep .p-dropdown-panel .p-dropdown-items .p-dropdown-item-group {
@@ -111,6 +112,7 @@ export interface IFormlySelectFieldConfig extends FormlyFieldConfig<ISelectProps
111
112
} )
112
113
export class SelectComponent extends FieldType < FormlyFieldConfig < ISelectProps > > implements OnInit {
113
114
115
+ protected cd : ChangeDetectorRef = inject ( ChangeDetectorRef ) ;
114
116
/** Default properties */
115
117
defaultOptions : Partial < FormlyFieldConfig < ISelectProps > > = {
116
118
defaultValue : null ,
@@ -131,7 +133,7 @@ export class SelectComponent extends FieldType<FormlyFieldConfig<ISelectProps>>
131
133
}
132
134
} ;
133
135
134
- selectOptions : any [ ] = [ ] ;
136
+ selectOptions : any [ ] ;
135
137
136
138
ngOnInit ( ) : void {
137
139
if ( ! isObservable ( this . props . options ) ) {
@@ -156,6 +158,7 @@ export class SelectComponent extends FieldType<FormlyFieldConfig<ISelectProps>>
156
158
} else {
157
159
this . selectOptions = this . props . sort ? this . sortOptions ( options ) : options ;
158
160
}
161
+ this . cd . markForCheck ( ) ;
159
162
} ) ;
160
163
}
161
164
0 commit comments