SlideShare a Scribd company logo
1 of 26
Copyright © Incyzr 2018
Dynamic Templates in Angular
OR How to Incorporate Dynamic Content into Your
Application
(both Templates and Components) without tears
Dr. Roger Kermode
CEO & Co-Founder, Incyzr – roger [at] incyzr.com
Industry Professor, UTS – roger.kermode [at] uts.edu.au
Copyright © Incyzr 2018
Attribution and Disclaimer
Attribution
•This talk is based largely on the content created by
Max NgWizard K’s Angular In Depth Blog posts
• “Exploring Angular DOM manipulation techniques using ViewContainerRef“
• https://blog.angularindepth.com/exploring-angular-dom-abstractions-80b3ebcfc02
• “Here is what you need to know about dynamic components in Angular
• https://blog.angularindepth.com/here-is-what-you-need-to-know-about-dynamic-
components-in-angular-ac1e96167f9e
Disclaimer
•I am not nor do I claim to be an Angular Developer / Expert or a
Professional Developer - any errors or omissions in this talk are
unintended and solely my responsibility!
Copyright © Incyzr 2018
Angular is Awesome…. but opinionated
• In comparison to another popular framework “X” the following has
been said
• If makes little sense to compare “X” with Angular, they’re so different -
If you were to liken “X” to a screwdriver then the Angular equivalent would
be the entire toolbox.
• Opinionated and fully featured design affords a lot of power
• But what if you need to step a little outside those guidelines?
Copyright © Incyzr 2018
Exploring Angular DOM
manipulation techniques using
ViewContainerRef
https://blog.angularindepth.com/exploring-angular-dom-
abstractions-80b3ebcfc02
Copyright © Incyzr 2018
Refs in Angular
Copyright © Incyzr 2018
@ViewChild
• Provides the mechanism for the
component to access content in
the template
• Elements
• Components
• Can use @ViewChildren to
access multiple of same type
• Returns QueryList that needs to be
processed into an array
Copyright © Incyzr 2018
ElementRef
• Provides access to the HTML
element
• Use .nativeElement to access
DOM properties
• Not to be used if at all possible
• If manipulating sizes better to use
@HostBinding(style.top.px) etc
instead
Copyright © Incyzr 2018
TemplateRef part1
• Build on HTML Templates
• Template content removed
from DOM
• Can be inserted elsewhere
Copyright © Incyzr 2018
TemplateRef Part2
• Still build on HTML Templates
• Core part of Angular for
rendering views
Copyright © Incyzr 2018
ViewRef
• Views are fundamental building
blocks of the application UI.
• They are the smallest grouping
of elements that can be created
/ destroyed together
• Angular supports 2 types of
view
• Embedded Views link to a Template
• Host Views linked to a Component
Copyright © Incyzr 2018
ViewContainerRef
• ViewContainerRef represents a
container where one or more
views can be rendered.
• Views are appended AFTER
the element bound to the
ViewContainer.
• Also see this in the DOM with
• <ng-container>
• <ng-content>
• <router-outlet>
Copyright © Incyzr 2018
View Fun with Refs
Copyright © Incyzr 2018
Manipulating Views
• ViewContainer provides an
API for manipulating views
• Once created, a view can
be inserted into the DOM
Copyright © Incyzr 2018
Creating View
• Now for the fun part…
• Views can also be created in code via components
Copyright © Incyzr 2018
ngTemplateOutlet & ngComponentOutlet
• Angular even provides a
shortcut that removes the need
for writing code
• ngTemplateOutlet inserts a
embedded view
• ngComponentOutlet inserts a
host view (instantiates a
component
Copyright © Incyzr 2018
Dynamic Components
Source: https://blog.angularindepth.com/here-is-what-you-need-
to-know-about-dynamic-components-in-angular-ac1e96167f9e
Copyright © Incyzr 2018
What about Dynamic Content?
• Not all content can be predefined in templates at the time of coding
• Need a way to pull rich content that includes angular components,
directives etc. from a database and instantiates them on the fly
• Some Examples
• Markdown / WYSIWIG Editor
• Template is modified and needs to have components insideit
• Rich User Defined Content from a Database
• More than just a comment, want multiple links with custom behaviors (e.g. contextual
drag and drop)
Copyright © Incyzr 2018
How AngularJs Solved this Problem
• Define the template
• Use the built in compiler
• Insert the content into the DOM
• Simple!
• Angular is different
• No equivalent to $compile
• Setting innerHTML doesn’t work
• Content is sanitized
• Components NOT instantiated
• So we need to create a component
dynamically and then install it
• What would this look like…..
Copyright © Incyzr 2018
Anatomy of Angular Component Creation
• How could we create a component on the fly?
• Good starting point is to look at how lazy loaded
components are instantiated….
• Ugh - This is a complicated process:
1. Angular Expects Modules with components inside SO ->
2. Need to create a module on the fly that contains the
component AND
3. Ensure that Dependency Injection is setup properly AND
4. Ensure that Module is injected properly
• For full details see the blog post…
• Still doesn’t get us to where we need to be
• Dynamic templates – i.e. not defined at run time
• Support for Components inside the templates to enable
complex UI behaviors
Copyright © Incyzr 2018
Dynamic Component
Creation….
Copyright © Incyzr 2018
Observations
• Lot of heavy lifting need to support dynamic content…
• Hasn’t someone come up with a solution and packaged this up
already?
• Yes they have….
• Lacolaco (Suguru Inatomi) created the ng-dynamic package
• https://github.com/lacolaco/ng-dynamic
Copyright © Incyzr 2018
lacolaco/ng-dynamic
• Package provides
• dynamic-html Component
• render an HTML string, potentially
provided from a database
• BUT does not handle template
interpolation and conditionals i.e.
{{foo}}, *ngIf
• *dynamicComponent Directive
• creates a dynamic component
• Renders the HTML and all the
template interpolation and
conditionals
Copyright © Incyzr 2018
lacolaco/ng-dynamic: dynamic-html component
Copyright © Incyzr 2018
lacolaco/ng-dynamic: *dynamicComponent Directive
Copyright © Incyzr 2018
Incyzr– Deep Linked Comment Example
Comment String from Database
Embedded
Components
“This is the first comment on
<zr-entity
zr-entity-type='person’
zr-entity-name='Roger Kermode’
zr-entity-id='5ad67dfeaea7b64479a6ea9a'>
Roger
</zr-entity>
, he lives in
<zr-entity
zr-entity-type='place’
zr-entity-name='Sydney’
zr-entity-id='5ad67dfdaea7b64479a6ea69'>
Sydney
</zr-entity>”
zr-comment-item.component.pug
Rendered Output
zr-entity.component.pug
Copyright © Incyzr 2018
Thank You
Dr. Roger Kermode
roger [at] incyzr.com

More Related Content

What's hot

AngularJS Vs Angular: Understanding the Differences
AngularJS Vs Angular: Understanding the DifferencesAngularJS Vs Angular: Understanding the Differences
AngularJS Vs Angular: Understanding the DifferencesTechtic Solutions
 
The Ultimate Getting Started with Angular Workshop - Devoxx UK 2017
The Ultimate Getting Started with Angular Workshop - Devoxx UK 2017The Ultimate Getting Started with Angular Workshop - Devoxx UK 2017
The Ultimate Getting Started with Angular Workshop - Devoxx UK 2017Matt Raible
 
Angular interview questions
Angular interview questionsAngular interview questions
Angular interview questionsGoa App
 
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...Edureka!
 
Introduction To Angular 4 - J2I
Introduction To Angular 4 - J2IIntroduction To Angular 4 - J2I
Introduction To Angular 4 - J2INader Debbabi
 
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...Edureka!
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshareSaleemMalik52
 
Mastering angular - Dot Net Tricks
Mastering angular - Dot Net TricksMastering angular - Dot Net Tricks
Mastering angular - Dot Net TricksGaurav Singh
 
S60 3rd FP2 Widgets
S60 3rd FP2 WidgetsS60 3rd FP2 Widgets
S60 3rd FP2 Widgetsromek
 
Angular 10 course_content
Angular 10 course_contentAngular 10 course_content
Angular 10 course_contentNAVEENSAGGAM1
 
Web components are the future of the web - Take advantage of new web technolo...
Web components are the future of the web - Take advantage of new web technolo...Web components are the future of the web - Take advantage of new web technolo...
Web components are the future of the web - Take advantage of new web technolo...Marios Fakiolas
 
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Knoldus Inc.
 
Major project 2013 14
Major project 2013 14Major project 2013 14
Major project 2013 14Parag Garg
 
Beginning iOS6 Development CH03 Handlling Basic Interaction
Beginning iOS6 Development CH03 Handlling Basic InteractionBeginning iOS6 Development CH03 Handlling Basic Interaction
Beginning iOS6 Development CH03 Handlling Basic InteractionAbdulrazzaq Alnajjar
 
Angular 4 Introduction Tutorial
Angular 4 Introduction TutorialAngular 4 Introduction Tutorial
Angular 4 Introduction TutorialScott Lee
 

What's hot (20)

AngularJS Vs Angular: Understanding the Differences
AngularJS Vs Angular: Understanding the DifferencesAngularJS Vs Angular: Understanding the Differences
AngularJS Vs Angular: Understanding the Differences
 
The Ultimate Getting Started with Angular Workshop - Devoxx UK 2017
The Ultimate Getting Started with Angular Workshop - Devoxx UK 2017The Ultimate Getting Started with Angular Workshop - Devoxx UK 2017
The Ultimate Getting Started with Angular Workshop - Devoxx UK 2017
 
Angular 2
Angular 2Angular 2
Angular 2
 
Angular interview questions
Angular interview questionsAngular interview questions
Angular interview questions
 
Angular 9
Angular 9 Angular 9
Angular 9
 
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...
Selenium Page Object Model Using Page Factory | Selenium Tutorial For Beginne...
 
Introduction To Angular 4 - J2I
Introduction To Angular 4 - J2IIntroduction To Angular 4 - J2I
Introduction To Angular 4 - J2I
 
Angular4 tutorial
Angular4 tutorialAngular4 tutorial
Angular4 tutorial
 
Angular vs react
Angular vs reactAngular vs react
Angular vs react
 
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
What Is Angular 2 | Angular 2 Tutorial For Beginners | Angular Training | Edu...
 
Angular kickstart slideshare
Angular kickstart   slideshareAngular kickstart   slideshare
Angular kickstart slideshare
 
Mastering angular - Dot Net Tricks
Mastering angular - Dot Net TricksMastering angular - Dot Net Tricks
Mastering angular - Dot Net Tricks
 
S60 3rd FP2 Widgets
S60 3rd FP2 WidgetsS60 3rd FP2 Widgets
S60 3rd FP2 Widgets
 
Angular 10 course_content
Angular 10 course_contentAngular 10 course_content
Angular 10 course_content
 
Web components are the future of the web - Take advantage of new web technolo...
Web components are the future of the web - Take advantage of new web technolo...Web components are the future of the web - Take advantage of new web technolo...
Web components are the future of the web - Take advantage of new web technolo...
 
Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2Routing & Navigating Pages in Angular 2
Routing & Navigating Pages in Angular 2
 
Major project 2013 14
Major project 2013 14Major project 2013 14
Major project 2013 14
 
Beginning iOS6 Development CH03 Handlling Basic Interaction
Beginning iOS6 Development CH03 Handlling Basic InteractionBeginning iOS6 Development CH03 Handlling Basic Interaction
Beginning iOS6 Development CH03 Handlling Basic Interaction
 
Alloy backbone
Alloy backboneAlloy backbone
Alloy backbone
 
Angular 4 Introduction Tutorial
Angular 4 Introduction TutorialAngular 4 Introduction Tutorial
Angular 4 Introduction Tutorial
 

Similar to Ng Sydney Dynamic Templates Talk - 18 April 2018

Web Components
Web ComponentsWeb Components
Web ComponentsFITC
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectJadson Santos
 
Web Components
Web ComponentsWeb Components
Web ComponentsFITC
 
Build Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponentsBuild Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponentsGil Fink
 
Web component driven development
Web component driven developmentWeb component driven development
Web component driven developmentGil Fink
 
Evolution and History of Angular as Web Development Platform.pdf
Evolution and History of Angular as Web Development Platform.pdfEvolution and History of Angular as Web Development Platform.pdf
Evolution and History of Angular as Web Development Platform.pdfiFour Technolab Pvt. Ltd.
 
Weekly Meeting: Basic Design Pattern
Weekly Meeting: Basic Design PatternWeekly Meeting: Basic Design Pattern
Weekly Meeting: Basic Design PatternNguyen Trung Kien
 
Web components
Web componentsWeb components
Web componentsGil Fink
 
Angular.ppt
Angular.pptAngular.ppt
Angular.pptMytrux1
 
Web components - The Future is Here
Web components - The Future is HereWeb components - The Future is Here
Web components - The Future is HereGil Fink
 
Web components, so close!
Web components, so close!Web components, so close!
Web components, so close!Aleks Zinevych
 
AngularJS Beginners Workshop
AngularJS Beginners WorkshopAngularJS Beginners Workshop
AngularJS Beginners WorkshopSathish VJ
 
How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...
How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...
How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...Azilen Technologies Pvt. Ltd.
 
Angular js Online Training
Angular js Online TrainingAngular js Online Training
Angular js Online TrainingLearntek1
 

Similar to Ng Sydney Dynamic Templates Talk - 18 April 2018 (20)

Advanced angular
Advanced angularAdvanced angular
Advanced angular
 
Web Components
Web ComponentsWeb Components
Web Components
 
Introduction to angular with a simple but complete project
Introduction to angular with a simple but complete projectIntroduction to angular with a simple but complete project
Introduction to angular with a simple but complete project
 
Angular
AngularAngular
Angular
 
What's new in Angular 2?
What's new in Angular 2?What's new in Angular 2?
What's new in Angular 2?
 
Web Components
Web ComponentsWeb Components
Web Components
 
Build Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponentsBuild Reusable Web Components using HTML5 Web cComponents
Build Reusable Web Components using HTML5 Web cComponents
 
Web component driven development
Web component driven developmentWeb component driven development
Web component driven development
 
Evolution and History of Angular as Web Development Platform.pdf
Evolution and History of Angular as Web Development Platform.pdfEvolution and History of Angular as Web Development Platform.pdf
Evolution and History of Angular as Web Development Platform.pdf
 
Weekly Meeting: Basic Design Pattern
Weekly Meeting: Basic Design PatternWeekly Meeting: Basic Design Pattern
Weekly Meeting: Basic Design Pattern
 
Sitecore mvc
Sitecore mvcSitecore mvc
Sitecore mvc
 
Web components
Web componentsWeb components
Web components
 
Angular.ppt
Angular.pptAngular.ppt
Angular.ppt
 
Web components - The Future is Here
Web components - The Future is HereWeb components - The Future is Here
Web components - The Future is Here
 
Web components, so close!
Web components, so close!Web components, so close!
Web components, so close!
 
AngularJS Beginners Workshop
AngularJS Beginners WorkshopAngularJS Beginners Workshop
AngularJS Beginners Workshop
 
How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...
How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...
How to create an angular 2.0 application in liferay dxp to fetch the ootb adv...
 
Angular js
Angular jsAngular js
Angular js
 
Angular js Online Training
Angular js Online TrainingAngular js Online Training
Angular js Online Training
 
Angular js
Angular jsAngular js
Angular js
 

Recently uploaded

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 

Recently uploaded (20)

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 

Ng Sydney Dynamic Templates Talk - 18 April 2018

  • 1. Copyright © Incyzr 2018 Dynamic Templates in Angular OR How to Incorporate Dynamic Content into Your Application (both Templates and Components) without tears Dr. Roger Kermode CEO & Co-Founder, Incyzr – roger [at] incyzr.com Industry Professor, UTS – roger.kermode [at] uts.edu.au
  • 2. Copyright © Incyzr 2018 Attribution and Disclaimer Attribution •This talk is based largely on the content created by Max NgWizard K’s Angular In Depth Blog posts • “Exploring Angular DOM manipulation techniques using ViewContainerRef“ • https://blog.angularindepth.com/exploring-angular-dom-abstractions-80b3ebcfc02 • “Here is what you need to know about dynamic components in Angular • https://blog.angularindepth.com/here-is-what-you-need-to-know-about-dynamic- components-in-angular-ac1e96167f9e Disclaimer •I am not nor do I claim to be an Angular Developer / Expert or a Professional Developer - any errors or omissions in this talk are unintended and solely my responsibility!
  • 3. Copyright © Incyzr 2018 Angular is Awesome…. but opinionated • In comparison to another popular framework “X” the following has been said • If makes little sense to compare “X” with Angular, they’re so different - If you were to liken “X” to a screwdriver then the Angular equivalent would be the entire toolbox. • Opinionated and fully featured design affords a lot of power • But what if you need to step a little outside those guidelines?
  • 4. Copyright © Incyzr 2018 Exploring Angular DOM manipulation techniques using ViewContainerRef https://blog.angularindepth.com/exploring-angular-dom- abstractions-80b3ebcfc02
  • 5. Copyright © Incyzr 2018 Refs in Angular
  • 6. Copyright © Incyzr 2018 @ViewChild • Provides the mechanism for the component to access content in the template • Elements • Components • Can use @ViewChildren to access multiple of same type • Returns QueryList that needs to be processed into an array
  • 7. Copyright © Incyzr 2018 ElementRef • Provides access to the HTML element • Use .nativeElement to access DOM properties • Not to be used if at all possible • If manipulating sizes better to use @HostBinding(style.top.px) etc instead
  • 8. Copyright © Incyzr 2018 TemplateRef part1 • Build on HTML Templates • Template content removed from DOM • Can be inserted elsewhere
  • 9. Copyright © Incyzr 2018 TemplateRef Part2 • Still build on HTML Templates • Core part of Angular for rendering views
  • 10. Copyright © Incyzr 2018 ViewRef • Views are fundamental building blocks of the application UI. • They are the smallest grouping of elements that can be created / destroyed together • Angular supports 2 types of view • Embedded Views link to a Template • Host Views linked to a Component
  • 11. Copyright © Incyzr 2018 ViewContainerRef • ViewContainerRef represents a container where one or more views can be rendered. • Views are appended AFTER the element bound to the ViewContainer. • Also see this in the DOM with • <ng-container> • <ng-content> • <router-outlet>
  • 12. Copyright © Incyzr 2018 View Fun with Refs
  • 13. Copyright © Incyzr 2018 Manipulating Views • ViewContainer provides an API for manipulating views • Once created, a view can be inserted into the DOM
  • 14. Copyright © Incyzr 2018 Creating View • Now for the fun part… • Views can also be created in code via components
  • 15. Copyright © Incyzr 2018 ngTemplateOutlet & ngComponentOutlet • Angular even provides a shortcut that removes the need for writing code • ngTemplateOutlet inserts a embedded view • ngComponentOutlet inserts a host view (instantiates a component
  • 16. Copyright © Incyzr 2018 Dynamic Components Source: https://blog.angularindepth.com/here-is-what-you-need- to-know-about-dynamic-components-in-angular-ac1e96167f9e
  • 17. Copyright © Incyzr 2018 What about Dynamic Content? • Not all content can be predefined in templates at the time of coding • Need a way to pull rich content that includes angular components, directives etc. from a database and instantiates them on the fly • Some Examples • Markdown / WYSIWIG Editor • Template is modified and needs to have components insideit • Rich User Defined Content from a Database • More than just a comment, want multiple links with custom behaviors (e.g. contextual drag and drop)
  • 18. Copyright © Incyzr 2018 How AngularJs Solved this Problem • Define the template • Use the built in compiler • Insert the content into the DOM • Simple! • Angular is different • No equivalent to $compile • Setting innerHTML doesn’t work • Content is sanitized • Components NOT instantiated • So we need to create a component dynamically and then install it • What would this look like…..
  • 19. Copyright © Incyzr 2018 Anatomy of Angular Component Creation • How could we create a component on the fly? • Good starting point is to look at how lazy loaded components are instantiated…. • Ugh - This is a complicated process: 1. Angular Expects Modules with components inside SO -> 2. Need to create a module on the fly that contains the component AND 3. Ensure that Dependency Injection is setup properly AND 4. Ensure that Module is injected properly • For full details see the blog post… • Still doesn’t get us to where we need to be • Dynamic templates – i.e. not defined at run time • Support for Components inside the templates to enable complex UI behaviors
  • 20. Copyright © Incyzr 2018 Dynamic Component Creation….
  • 21. Copyright © Incyzr 2018 Observations • Lot of heavy lifting need to support dynamic content… • Hasn’t someone come up with a solution and packaged this up already? • Yes they have…. • Lacolaco (Suguru Inatomi) created the ng-dynamic package • https://github.com/lacolaco/ng-dynamic
  • 22. Copyright © Incyzr 2018 lacolaco/ng-dynamic • Package provides • dynamic-html Component • render an HTML string, potentially provided from a database • BUT does not handle template interpolation and conditionals i.e. {{foo}}, *ngIf • *dynamicComponent Directive • creates a dynamic component • Renders the HTML and all the template interpolation and conditionals
  • 23. Copyright © Incyzr 2018 lacolaco/ng-dynamic: dynamic-html component
  • 24. Copyright © Incyzr 2018 lacolaco/ng-dynamic: *dynamicComponent Directive
  • 25. Copyright © Incyzr 2018 Incyzr– Deep Linked Comment Example Comment String from Database Embedded Components “This is the first comment on <zr-entity zr-entity-type='person’ zr-entity-name='Roger Kermode’ zr-entity-id='5ad67dfeaea7b64479a6ea9a'> Roger </zr-entity> , he lives in <zr-entity zr-entity-type='place’ zr-entity-name='Sydney’ zr-entity-id='5ad67dfdaea7b64479a6ea69'> Sydney </zr-entity>” zr-comment-item.component.pug Rendered Output zr-entity.component.pug
  • 26. Copyright © Incyzr 2018 Thank You Dr. Roger Kermode roger [at] incyzr.com

Editor's Notes

  1. In
  2. ANatom
  3. lactyh