@@ -32,6 +32,7 @@ export class MaterializeDirective implements AfterViewInit,DoCheck,OnChanges,OnD
32
32
private _params :[ any ] = null ;
33
33
private _functionName :string = null ;
34
34
private previousValue = null ;
35
+ private _waitFunction : any = { } ;
35
36
36
37
private changeListenerShouldBeAdded = true ;
37
38
@@ -156,37 +157,47 @@ export class MaterializeDirective implements AfterViewInit,DoCheck,OnChanges,OnD
156
157
157
158
this . performLocalElementUpdates ( ) ;
158
159
}
159
-
160
+
160
161
private performLocalElementUpdates ( functionName = this . _functionName ) {
161
- if ( functionName ) {
162
- const jQueryElement = $ ( this . _el . nativeElement ) ;
163
- if ( jQueryElement [ functionName ] ) {
164
- if ( this . _params ) {
165
- if ( this . _params instanceof Array ) {
166
- jQueryElement [ functionName ] ( ...this . _params ) ;
167
- } else {
168
- throw new Error ( "Params has to be an array." )
169
- }
170
- } else {
171
- jQueryElement [ functionName ] ( ) ;
172
- }
173
- } else {
174
- // fallback to running this function on the global Materialize object
175
- if ( Materialize [ functionName ] ) {
162
+ if ( this . _waitFunction [ functionName ] ) {
163
+ return ;
164
+ }
165
+
166
+ this . _waitFunction [ functionName ] = true ;
167
+
168
+ $ ( document ) . ready ( ( ) => {
169
+ this . _waitFunction [ functionName ] = false ;
170
+
171
+ if ( functionName ) {
172
+ const jQueryElement = $ ( this . _el . nativeElement ) ;
173
+ if ( jQueryElement [ functionName ] ) {
176
174
if ( this . _params ) {
177
175
if ( this . _params instanceof Array ) {
178
- Materialize [ functionName ] ( ...this . _params ) ;
176
+ jQueryElement [ functionName ] ( ...this . _params ) ;
179
177
} else {
180
- throw new Error ( "Params has to be an array." )
178
+ throw new Error ( "Params has to be an array." ) ;
181
179
}
182
180
} else {
183
- Materialize [ functionName ] ( ) ;
181
+ jQueryElement [ functionName ] ( ) ;
184
182
}
185
183
} else {
186
- throw new Error ( "Couldn't find materialize function ''" + functionName + "' on element or the global Materialize object." ) ;
184
+ // fallback to running this function on the global Materialize object
185
+ if ( Materialize [ functionName ] ) {
186
+ if ( this . _params ) {
187
+ if ( this . _params instanceof Array ) {
188
+ Materialize [ functionName ] ( ...this . _params ) ;
189
+ } else {
190
+ throw new Error ( "Params has to be an array." ) ;
191
+ }
192
+ } else {
193
+ Materialize [ functionName ] ( ) ;
194
+ }
195
+ } else {
196
+ throw new Error ( "Couldn't find materialize function ''" + functionName + "' on element or the global Materialize object." ) ;
197
+ }
187
198
}
188
199
}
189
- }
200
+ } ) ;
190
201
}
191
202
192
203
private isTooltip ( ) {
@@ -218,4 +229,4 @@ export class MaterializeDirective implements AfterViewInit,DoCheck,OnChanges,OnD
218
229
event.initEvent(eventType, true, true);
219
230
}
220
231
target.dispatchEvent(event);
221
- };*/
232
+ };*/
0 commit comments