Dynamic content with Angular
-
Upload
filip-bruun-bech-larsen -
Category
Technology
-
view
386 -
download
0
Transcript of Dynamic content with Angular
Dynamic content with
Angulara journey with @filipbech
@IMPACTdigitaldk
https://developers.google.com/experts/people/filip-bruun-bech-larsen
Why
• We build for CMS-editors, so we need Angular to
behave in that context
• When Angular2 (old name) was announced it
seemed so awesome…
Bootstrapping multiple
applications
• its a little harder to maintain state between
applications (but possible)
• the cms now needs to know what components are
angular-components, so they can all be
bootstrapped.(and their DOM-nodes if multiple of the
same component)
Initial data
• We need to feed data (settings, initial data) into
some of the components (from the cms), and put
content inside them.
Because
• Root-components cannot have inputs
• Root-components cannot use content-projection
(transclusion)
https://github.com/angular/angular/issues/1858
• even though it works - it feels terrible and wrong!
• and we need the parser at runtime
• so no AOT and bad perf
Single Page Application
• so we can also share state between routes
• animate route-changes
• and much more…
We have too many routes
with no patterns
• “/“ is a frontpage
• “/om/os” is a content-page
• “/mejeri“ is a category-page
• “/mejeri/ost“ is a sub-category-page
• “/ost-i-skiver-mild-13-cheasy-200-g” is a product-page
Two issues with that
approach
• Need to build and invalidate the bundle’s cache
every time an editor makes a change
• Users get stuck on the route-config they get at first
load
In angular 1.x we could use templateFactory and
select a template based on the api-response
But we cannot do that in Angular 2+, because
there is no template-parser at runtime
Even though all the *ngIfs in the template are AOT
compiled into something more acceptable…
It still seems wrong to have it in the template!
The problem cascades
• When we go from one product-detail-page to
another product-detail-page…
• Refactor init-logic into ngOnChanges
or (if you are building a lib)
ANALYSE_FOR_ENTRY_COMPONE
NTS
Watch Sean Landsmans talk from ngVikings:
https://opbeat.com/community/posts/understanding-aot-and-dynamic-components-in-angular-by-sean-landsman/
SEO, social previews
and
faster perceived load-
timesAngular Universal is so hot right now… (going into core)
The idea
• server.module and a client.module
• they both import the app.module
• server and client module then replaces the
dependencies (through the universal-module) that
are different with appropriate environment-versions
(eg. xhr or node-fetch, DOM or virtual-dom)
Maintaining statewe want to maintain state, so we don’t re-do all fetches
and calculations when the client boots up
We made it to nirvana
https://github.com/filipbech/ng2-dynamic-spa
Thank you
@filipbech@IMPACTdigitaldk
I’ll tweet a link to the slides in a minute