SlideShare a Scribd company logo
1 of 39
Web components in
Angular (Angular Elements)
1
Copyright ©2019, Walking Tree Technologies
● An IT Software and Service provider company.
● We act as an extended team for the customers across the globe like Capgemini, Tech Mahindra, Tibco, HP,
Infosys, Qualcomm, TCS to name a few and deliver end-to-end products and solutions to ensure “Great User
Experience.”
● Specialized in technology solutions from designing, development, quality assurance, maintenance and
support, consulting, training and skill augmentation services
● Technical Expertise in Angular, Blockchain, Microservices, React, Sencha ExtJS, Xamarin.
● Recognized as 50 Best Indian founded companies by The Silicon Review.
WHAT DO WE DO?
2
Copyright ©2019, Walking Tree Technologies
About Me
Subbu Nama
Technical Lead
● Subbu has worked in the technology
industry for over 8 years.
● Has good exposure on different domains
● Subbu is a full stack developer, interested
in tools and techniques for visualization
on the web and enjoys working with web
technologies.
3
Copyright ©2019, Walking Tree Technologies
AGENDA
Assimilation of
Elements
Best practices Browser Support
4
Web Components
Relevance
Angular Elements
Copyright ©2019, Walking Tree Technologies 5
WEB COMPONENTS RELEVANCE
Main Technologies
Why?
What?
V0 Example
V1 Example
5
Copyright ©2019, Walking Tree Technologies
Why?
6
Copyright ©2019, Walking Tree Technologies 7
function numbersSum(even, ...numbers){
var sum=0;
if (!numbers){
numbers=[];
}
numbers.forEach( (number) => {
if (number%2 == 0 && even){
sum=sum+number;
}else if (number%2 != 0 && !even){
sum=sum+number;
}
});
return sum;
}
SUM OF EVEN/ODD NUMBERS
Copyright ©2019, Walking Tree Technologies 8
What?
Copyright ©2019, Walking Tree Technologies
Web component provides the much-needed relief, it’s a suite of different
technologies allowing you to create reusable custom elements with their
functionality encapsulated away from the rest of your code and utilize them in
your web apps.
9
Copyright ©2019, Walking Tree Technologies 10
Main Technologies
Copyright ©2019, Walking Tree Technologies
● Custom Elements
● Shadow DOM
● HTML Templates
11
Three Main Technologies
Copyright ©2019, Walking Tree Technologies 12
V0
Copyright ©2019, Walking Tree Technologies 13
var sayHello = Object.create(HTMLElement.prototype);
sayHello.createdCallback = function() {
this.innerHTML = "<button>Say, Hello</button>";
};
document.registerElement('say-hello', {prototype: sayHello});
...
button.addEventListener("click", function(){
alert("Hello World");
});
V0 Example
Copyright ©2019, Walking Tree Technologies 14
V1
Copyright ©2019, Walking Tree Technologies 15
V1 Example
const template = document.createElement('template');
template.innerHTML = `<button>Say, Hello</button>`;
class SayHello extends HTMLElement {
...
this.attachShadow({mode: 'open'});
this.shadowRoot.appendChild(template.content.cloneNode(true));
….
button.addEventListener("click", function(){
alert("Hello!, you are doing good");
});
}}
window.customElements.define('say-hello', SayHello);
Copyright ©2019, Walking Tree Technologies 1616
Anatomy Of Web Components in Angular (Angular Elements)
Define component as Angular Element
What is component?
Encapsulation methods of component
Package build files
16
Copyright ©2019, Walking Tree Technologies 17
What is Component?
Copyright ©2019, Walking Tree Technologies
Components are the most basic UI building block of an Angular
application. Angular component provides configuration metadata that
determines how the component should be processed, instantiated, and
used at runtime
18
Copyright ©2019, Walking Tree Technologies 19
Encapsulation Methods
Copyright ©2019, Walking Tree Technologies 20
ViewEncapsulation.None
Copyright ©2019, Walking Tree Technologies 21
ViewEncapsulation.Emulated
Copyright ©2019, Walking Tree Technologies 22
ViewEncapsulation.ShadowDom
Copyright ©2019, Walking Tree Technologies 23
Define Angular Elements
Copyright ©2019, Walking Tree Technologies
@Component({
...
encapsulation:ViewEncapsulation.ShadowDom
})
export class ShareDataComponent {
@Input() info:any = {};
@Output() message = new EventEmitter();
userInput:any="";
sendMessage(){
this.message.emit("Hello "+this.info.name+", "+this.userInput);
}
}
24
Copyright ©2019, Walking Tree Technologies 25
Component Functionality
Copyright ©2019, Walking Tree Technologies 26
$ ng add @angular/elements --name=AngularElements
Add Angular elements dependency
Copyright ©2019, Walking Tree Technologies 27
@NgModule({
….
entryComponents: [ShareDataComponent]
})
export class AppModule {
constructor(private injector: Injector) {
const customElement = createCustomElement(ShareDataComponent, { injector });
customElements.define('input-output', customElement);
}
ngDoBootstrap() {}
}
Define Custom element
Copyright ©2019, Walking Tree Technologies 28
Packaging Build Files
Copyright ©2019, Walking Tree Technologies 29
...
(async function build() {
const files = [
'./dist/AngularElements/runtime.js',
'./dist/AngularElements/polyfills.js',
'./dist/AngularElements/scripts.js',
'./dist/AngularElements/main.js'
];
await fs.ensureDir('elements');
await concat(files, 'elements/input-output-element.js');
})();
Copyright ©2019, Walking Tree Technologies 30
"build": "ng build --prod --output-hashing=none && node make-elements.js"
$ npm run build
Copyright ©2019, Walking Tree Technologies 31
Assimilation Of Angular Elements
Copyright ©2019, Walking Tree Technologies 32
...
<script src="input-output-element.js" ></script>
...
<input-output></input-output>
<script>
var info={name:'WTT'};
var element = document.querySelector('input-output');
element.info=info;
element.addEventListener('message', function(data){
alert(data.detail);
});
</script>
...
Copyright ©2019, Walking Tree Technologies 33
Copyright ©2019, Walking Tree Technologies 34
Best Practices
Copyright ©2019, Walking Tree Technologies 35
1) Create shadow root to encapsulate styles
2) Place any children the element creates into its shadow root
3) Set a :host display style unless you prefer the default of inline
4) Add a :host display style that respects the attributes.
5) Always accept primitive data (strings, numbers, booleans) as either
attributes or properties.
Copyright ©2019, Walking Tree Technologies 36
Browser Support
Copyright ©2019, Walking Tree Technologies 37
Copyright ©2019, Walking Tree Technologies
Questions and Answers
38
Copyright ©2019, Walking Tree Technologies
Thank You!
39

More Related Content

Similar to Web components in Angular (Angular Elements) | Walkingtree Technologies

A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...DataLeader.io
 
VMware's Journey to Deliver Developer Portals as a Service
VMware's Journey to Deliver Developer Portals as a ServiceVMware's Journey to Deliver Developer Portals as a Service
VMware's Journey to Deliver Developer Portals as a ServicePronovix
 
Magic of web components
Magic of web componentsMagic of web components
Magic of web componentsHYS Enterprise
 
Best Practices & Lessons Learned from the field on EMC Documentum xCP 2.0
Best Practices & Lessons Learned from the field on EMC Documentum xCP 2.0Best Practices & Lessons Learned from the field on EMC Documentum xCP 2.0
Best Practices & Lessons Learned from the field on EMC Documentum xCP 2.0Haytham Ghandour
 
Java springboot microservice - Accenture Technology Meetup
Java springboot microservice - Accenture Technology MeetupJava springboot microservice - Accenture Technology Meetup
Java springboot microservice - Accenture Technology MeetupAccenture Hungary
 
Best Practices for Scalable Monitoring (ENT310-S) - AWS re:Invent 2018
Best Practices for Scalable Monitoring (ENT310-S) - AWS re:Invent 2018Best Practices for Scalable Monitoring (ENT310-S) - AWS re:Invent 2018
Best Practices for Scalable Monitoring (ENT310-S) - AWS re:Invent 2018Amazon Web Services
 
AngularJS for Web and Mobile
 AngularJS for Web and Mobile AngularJS for Web and Mobile
AngularJS for Web and MobileRocket Software
 
OWASP Bay Area Meetup - DevSecOps the Kubernetes Way
OWASP Bay Area Meetup - DevSecOps the Kubernetes WayOWASP Bay Area Meetup - DevSecOps the Kubernetes Way
OWASP Bay Area Meetup - DevSecOps the Kubernetes WayJimmy Mesta
 
Leadership Session: Using AWS End User Computing Services for Your Modern Wor...
Leadership Session: Using AWS End User Computing Services for Your Modern Wor...Leadership Session: Using AWS End User Computing Services for Your Modern Wor...
Leadership Session: Using AWS End User Computing Services for Your Modern Wor...Amazon Web Services
 
Tracxn Global SaaS from India Startup Landscape - Feb 2015
Tracxn Global SaaS from India Startup Landscape - Feb 2015Tracxn Global SaaS from India Startup Landscape - Feb 2015
Tracxn Global SaaS from India Startup Landscape - Feb 2015Tracxn
 
Salesforce meetup | Lightning Web Component
Salesforce meetup | Lightning Web ComponentSalesforce meetup | Lightning Web Component
Salesforce meetup | Lightning Web ComponentAccenture Hungary
 
Creating an Effective Roadmap for Your Cloud Journey (ENT225-R1) - AWS re:Inv...
Creating an Effective Roadmap for Your Cloud Journey (ENT225-R1) - AWS re:Inv...Creating an Effective Roadmap for Your Cloud Journey (ENT225-R1) - AWS re:Inv...
Creating an Effective Roadmap for Your Cloud Journey (ENT225-R1) - AWS re:Inv...Amazon Web Services
 
An Introduction to Web Components
An Introduction to Web ComponentsAn Introduction to Web Components
An Introduction to Web ComponentsRed Pill Now
 
[NEW LAUNCH!] Introducing AWS IoT Things Graph (IOT366) - AWS re:Invent 2018
[NEW LAUNCH!] Introducing AWS IoT Things Graph (IOT366) - AWS re:Invent 2018[NEW LAUNCH!] Introducing AWS IoT Things Graph (IOT366) - AWS re:Invent 2018
[NEW LAUNCH!] Introducing AWS IoT Things Graph (IOT366) - AWS re:Invent 2018Amazon Web Services
 
Tips for Building IoT Applications Faster (IOT366) - AWS re:Invent 2018
Tips for Building IoT Applications Faster (IOT366) - AWS re:Invent 2018Tips for Building IoT Applications Faster (IOT366) - AWS re:Invent 2018
Tips for Building IoT Applications Faster (IOT366) - AWS re:Invent 2018Amazon Web Services
 

Similar to Web components in Angular (Angular Elements) | Walkingtree Technologies (20)

A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
A Microsoft Silverlight User Group Starter Kit Made Available for Everyone to...
 
VMware's Journey to Deliver Developer Portals as a Service
VMware's Journey to Deliver Developer Portals as a ServiceVMware's Journey to Deliver Developer Portals as a Service
VMware's Journey to Deliver Developer Portals as a Service
 
Magic of web components
Magic of web componentsMagic of web components
Magic of web components
 
Best Practices & Lessons Learned from the field on EMC Documentum xCP 2.0
Best Practices & Lessons Learned from the field on EMC Documentum xCP 2.0Best Practices & Lessons Learned from the field on EMC Documentum xCP 2.0
Best Practices & Lessons Learned from the field on EMC Documentum xCP 2.0
 
Java springboot microservice - Accenture Technology Meetup
Java springboot microservice - Accenture Technology MeetupJava springboot microservice - Accenture Technology Meetup
Java springboot microservice - Accenture Technology Meetup
 
Best Practices for Scalable Monitoring (ENT310-S) - AWS re:Invent 2018
Best Practices for Scalable Monitoring (ENT310-S) - AWS re:Invent 2018Best Practices for Scalable Monitoring (ENT310-S) - AWS re:Invent 2018
Best Practices for Scalable Monitoring (ENT310-S) - AWS re:Invent 2018
 
AngularJS for Web and Mobile
 AngularJS for Web and Mobile AngularJS for Web and Mobile
AngularJS for Web and Mobile
 
OWASP Bay Area Meetup - DevSecOps the Kubernetes Way
OWASP Bay Area Meetup - DevSecOps the Kubernetes WayOWASP Bay Area Meetup - DevSecOps the Kubernetes Way
OWASP Bay Area Meetup - DevSecOps the Kubernetes Way
 
Leadership Session: Using AWS End User Computing Services for Your Modern Wor...
Leadership Session: Using AWS End User Computing Services for Your Modern Wor...Leadership Session: Using AWS End User Computing Services for Your Modern Wor...
Leadership Session: Using AWS End User Computing Services for Your Modern Wor...
 
Tracxn Global SaaS from India Startup Landscape - Feb 2015
Tracxn Global SaaS from India Startup Landscape - Feb 2015Tracxn Global SaaS from India Startup Landscape - Feb 2015
Tracxn Global SaaS from India Startup Landscape - Feb 2015
 
YasirNew
YasirNewYasirNew
YasirNew
 
Salesforce meetup | Lightning Web Component
Salesforce meetup | Lightning Web ComponentSalesforce meetup | Lightning Web Component
Salesforce meetup | Lightning Web Component
 
Creating an Effective Roadmap for Your Cloud Journey (ENT225-R1) - AWS re:Inv...
Creating an Effective Roadmap for Your Cloud Journey (ENT225-R1) - AWS re:Inv...Creating an Effective Roadmap for Your Cloud Journey (ENT225-R1) - AWS re:Inv...
Creating an Effective Roadmap for Your Cloud Journey (ENT225-R1) - AWS re:Inv...
 
GulabMaurya
GulabMauryaGulabMaurya
GulabMaurya
 
Sst hackathon express
Sst hackathon expressSst hackathon express
Sst hackathon express
 
Tapas Ghosh
Tapas GhoshTapas Ghosh
Tapas Ghosh
 
An Introduction to Web Components
An Introduction to Web ComponentsAn Introduction to Web Components
An Introduction to Web Components
 
[NEW LAUNCH!] Introducing AWS IoT Things Graph (IOT366) - AWS re:Invent 2018
[NEW LAUNCH!] Introducing AWS IoT Things Graph (IOT366) - AWS re:Invent 2018[NEW LAUNCH!] Introducing AWS IoT Things Graph (IOT366) - AWS re:Invent 2018
[NEW LAUNCH!] Introducing AWS IoT Things Graph (IOT366) - AWS re:Invent 2018
 
Tips for Building IoT Applications Faster (IOT366) - AWS re:Invent 2018
Tips for Building IoT Applications Faster (IOT366) - AWS re:Invent 2018Tips for Building IoT Applications Faster (IOT366) - AWS re:Invent 2018
Tips for Building IoT Applications Faster (IOT366) - AWS re:Invent 2018
 
Ppt0000000
Ppt0000000Ppt0000000
Ppt0000000
 

Recently uploaded

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 

Recently uploaded (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 

Web components in Angular (Angular Elements) | Walkingtree Technologies

  • 1. Web components in Angular (Angular Elements) 1
  • 2. Copyright ©2019, Walking Tree Technologies ● An IT Software and Service provider company. ● We act as an extended team for the customers across the globe like Capgemini, Tech Mahindra, Tibco, HP, Infosys, Qualcomm, TCS to name a few and deliver end-to-end products and solutions to ensure “Great User Experience.” ● Specialized in technology solutions from designing, development, quality assurance, maintenance and support, consulting, training and skill augmentation services ● Technical Expertise in Angular, Blockchain, Microservices, React, Sencha ExtJS, Xamarin. ● Recognized as 50 Best Indian founded companies by The Silicon Review. WHAT DO WE DO? 2
  • 3. Copyright ©2019, Walking Tree Technologies About Me Subbu Nama Technical Lead ● Subbu has worked in the technology industry for over 8 years. ● Has good exposure on different domains ● Subbu is a full stack developer, interested in tools and techniques for visualization on the web and enjoys working with web technologies. 3
  • 4. Copyright ©2019, Walking Tree Technologies AGENDA Assimilation of Elements Best practices Browser Support 4 Web Components Relevance Angular Elements
  • 5. Copyright ©2019, Walking Tree Technologies 5 WEB COMPONENTS RELEVANCE Main Technologies Why? What? V0 Example V1 Example 5
  • 6. Copyright ©2019, Walking Tree Technologies Why? 6
  • 7. Copyright ©2019, Walking Tree Technologies 7 function numbersSum(even, ...numbers){ var sum=0; if (!numbers){ numbers=[]; } numbers.forEach( (number) => { if (number%2 == 0 && even){ sum=sum+number; }else if (number%2 != 0 && !even){ sum=sum+number; } }); return sum; } SUM OF EVEN/ODD NUMBERS
  • 8. Copyright ©2019, Walking Tree Technologies 8 What?
  • 9. Copyright ©2019, Walking Tree Technologies Web component provides the much-needed relief, it’s a suite of different technologies allowing you to create reusable custom elements with their functionality encapsulated away from the rest of your code and utilize them in your web apps. 9
  • 10. Copyright ©2019, Walking Tree Technologies 10 Main Technologies
  • 11. Copyright ©2019, Walking Tree Technologies ● Custom Elements ● Shadow DOM ● HTML Templates 11 Three Main Technologies
  • 12. Copyright ©2019, Walking Tree Technologies 12 V0
  • 13. Copyright ©2019, Walking Tree Technologies 13 var sayHello = Object.create(HTMLElement.prototype); sayHello.createdCallback = function() { this.innerHTML = "<button>Say, Hello</button>"; }; document.registerElement('say-hello', {prototype: sayHello}); ... button.addEventListener("click", function(){ alert("Hello World"); }); V0 Example
  • 14. Copyright ©2019, Walking Tree Technologies 14 V1
  • 15. Copyright ©2019, Walking Tree Technologies 15 V1 Example const template = document.createElement('template'); template.innerHTML = `<button>Say, Hello</button>`; class SayHello extends HTMLElement { ... this.attachShadow({mode: 'open'}); this.shadowRoot.appendChild(template.content.cloneNode(true)); …. button.addEventListener("click", function(){ alert("Hello!, you are doing good"); }); }} window.customElements.define('say-hello', SayHello);
  • 16. Copyright ©2019, Walking Tree Technologies 1616 Anatomy Of Web Components in Angular (Angular Elements) Define component as Angular Element What is component? Encapsulation methods of component Package build files 16
  • 17. Copyright ©2019, Walking Tree Technologies 17 What is Component?
  • 18. Copyright ©2019, Walking Tree Technologies Components are the most basic UI building block of an Angular application. Angular component provides configuration metadata that determines how the component should be processed, instantiated, and used at runtime 18
  • 19. Copyright ©2019, Walking Tree Technologies 19 Encapsulation Methods
  • 20. Copyright ©2019, Walking Tree Technologies 20 ViewEncapsulation.None
  • 21. Copyright ©2019, Walking Tree Technologies 21 ViewEncapsulation.Emulated
  • 22. Copyright ©2019, Walking Tree Technologies 22 ViewEncapsulation.ShadowDom
  • 23. Copyright ©2019, Walking Tree Technologies 23 Define Angular Elements
  • 24. Copyright ©2019, Walking Tree Technologies @Component({ ... encapsulation:ViewEncapsulation.ShadowDom }) export class ShareDataComponent { @Input() info:any = {}; @Output() message = new EventEmitter(); userInput:any=""; sendMessage(){ this.message.emit("Hello "+this.info.name+", "+this.userInput); } } 24
  • 25. Copyright ©2019, Walking Tree Technologies 25 Component Functionality
  • 26. Copyright ©2019, Walking Tree Technologies 26 $ ng add @angular/elements --name=AngularElements Add Angular elements dependency
  • 27. Copyright ©2019, Walking Tree Technologies 27 @NgModule({ …. entryComponents: [ShareDataComponent] }) export class AppModule { constructor(private injector: Injector) { const customElement = createCustomElement(ShareDataComponent, { injector }); customElements.define('input-output', customElement); } ngDoBootstrap() {} } Define Custom element
  • 28. Copyright ©2019, Walking Tree Technologies 28 Packaging Build Files
  • 29. Copyright ©2019, Walking Tree Technologies 29 ... (async function build() { const files = [ './dist/AngularElements/runtime.js', './dist/AngularElements/polyfills.js', './dist/AngularElements/scripts.js', './dist/AngularElements/main.js' ]; await fs.ensureDir('elements'); await concat(files, 'elements/input-output-element.js'); })();
  • 30. Copyright ©2019, Walking Tree Technologies 30 "build": "ng build --prod --output-hashing=none && node make-elements.js" $ npm run build
  • 31. Copyright ©2019, Walking Tree Technologies 31 Assimilation Of Angular Elements
  • 32. Copyright ©2019, Walking Tree Technologies 32 ... <script src="input-output-element.js" ></script> ... <input-output></input-output> <script> var info={name:'WTT'}; var element = document.querySelector('input-output'); element.info=info; element.addEventListener('message', function(data){ alert(data.detail); }); </script> ...
  • 33. Copyright ©2019, Walking Tree Technologies 33
  • 34. Copyright ©2019, Walking Tree Technologies 34 Best Practices
  • 35. Copyright ©2019, Walking Tree Technologies 35 1) Create shadow root to encapsulate styles 2) Place any children the element creates into its shadow root 3) Set a :host display style unless you prefer the default of inline 4) Add a :host display style that respects the attributes. 5) Always accept primitive data (strings, numbers, booleans) as either attributes or properties.
  • 36. Copyright ©2019, Walking Tree Technologies 36 Browser Support
  • 37. Copyright ©2019, Walking Tree Technologies 37
  • 38. Copyright ©2019, Walking Tree Technologies Questions and Answers 38
  • 39. Copyright ©2019, Walking Tree Technologies Thank You! 39