@@ -108,7 +108,77 @@ <h2>
108
108
loaded from the backend!
109
109
</ p >
110
110
111
- < h2 > Loading mechanism</ h2 >
111
+ < h2 > Using standard Angular template binding</ h2 >
112
+
113
+ < p >
114
+ Once our element is loaded we can use standard Angular template binding
115
+ syntax like
116
+ < code > [customerId]="customerId"</ code > and
117
+ < code > (customerDataChange)="handleCustomerDataChange($event)"</ code >
118
+ to pass in data and react to events. It works just as expected!
119
+ </ p >
120
+
121
+ < pre [highlight] ="codeExampleComponentBinding "> </ pre >
122
+
123
+ < h2 > Seamless lazy loading</ h2 >
124
+
125
+ < p >
126
+ As mentioned above, our goal is to lazy-load element to improve application
127
+ startup time by decreasing size of javascript which has to be downloaded
128
+ initially.
129
+ </ p >
130
+
131
+ < p >
132
+ Lazy loading with < code > *axLazyElements</ code > happens automatically
133
+ whenever the element is rendered in the template of some Angular component.
134
+ Consider the following example...
135
+ </ p >
136
+
137
+ < pre [highlight] ="codeExampleComponentLazy "> </ pre >
138
+
139
+ < p >
140
+ We're using
141
+ < code
142
+ > <your-org-customer-editor
143
+ *axLazyElement="url"> </your-org-customer-editor> </ code
144
+ >
145
+ in the components template but it will not trigger element loading just yet.
146
+ As we may notice, the element is wrapped in the
147
+ < code > <ng-container> </ng-container> </ code > which uses
148
+ < code > *ngIf</ code >
149
+ directive so our element is not rendered until we click the button...
150
+ </ p >
151
+
152
+ < blockquote class ="large ">
153
+ The loading of element will be triggered only after we clicked the button
154
+ and rendered element for real in the component template
155
+ </ blockquote >
156
+
157
+ < p >
158
+ To summarize, the element loading will be postponed until it was rendered in
159
+ the template of some component. This can happen in following cases...
160
+ </ p >
161
+
162
+ < ul >
163
+ < li > Angular component uses element in its template</ li >
164
+ < li >
165
+ Angular component uses element in its template conditionally
166
+ (< code > *ngIf</ code > , < code > *ngFor</ code > , ...) and the condition was
167
+ fulfilled
168
+ </ li >
169
+ < li >
170
+ User navigated to an Angular component which uses element in its template
171
+ (can be both eagerly or lazily loaded routes)
172
+ </ li >
173
+ </ ul >
174
+
175
+ < blockquote >
176
+ This also means that if we used element in a component that is displayed
177
+ straight from application startup, we would also trigger loading of the
178
+ element bundle so it will NOT be lazy in that case
179
+ </ blockquote >
180
+
181
+ < h2 > In-depth overview of loading mechanism</ h2 >
112
182
113
183
< p >
114
184
Loading starts only once we want to display an Angular component which
@@ -123,12 +193,21 @@ <h2>Loading mechanism</h2>
123
193
> ) and display it in place of the element...
124
194
</ li >
125
195
< li > Check if element was already loaded in the past</ li >
126
- < li > ✅ remove loading template and render given element instead! </ li >
196
+ < li > ✅ remove loading template and render given element instead</ li >
127
197
< li >
128
198
⬇️ create a < code > <script> </ code > tag with < code > src = url</ code > and
129
- handler for the < code > onload</ code >
130
- event to notify directive when element was loaded
199
+ handler for the < code > onload</ code > and < code > onerror</ code >
200
+ events to notify directive when element was loaded or failed to load
201
+ </ li >
202
+ < li > Append < code > <script> </ code > to the document body</ li >
203
+ < li > Once loaded, notify directive about the outcome</ li >
204
+ < li >
205
+ ✅ remove loading template and render given element when loading was
206
+ successful
207
+ </ li >
208
+ < li >
209
+ ❌ remove loading template and render error template (if provided) when
210
+ loading was not successful
131
211
</ li >
132
- < li > Append < code > <script> </ code > to the body</ li >
133
212
</ ol >
134
213
</ div >
0 commit comments