By Carmen Popoviciu and Pascal Precht a.k.a ng-duo
Shared publicly - Aug 1, 2013
Ever wonder why AngularJS is super-heroic? It is because our interns are superheroes.
Shared publicly - Oct 23, 2014
Ever wonder why the Angular community is so awesome? Because it has superheroes as well.
+1Web Components are a collection of standards that change the way we build web applications.
HTML Templates - Inert chunks of clonable DOM
Shadow DOM - Style & DOM encapsulation
Custom Elements - Define and use new DOM elements
HTML Imports - Include other HTML documents
HTML Templates - Inert chunks of clonable DOM
Shadow DOM - Style & DOM encapsulation
Custom Elements - Define and use new DOM elements
HTML Imports - Include other HTML documents
Inert chunks of clonable DOM that can be activated for later use.
<template id="mytemplate"> <img src="" alt="great image"> <div class="comment"></div> </template>
var t = document.querySelector('#mytemplate'); // set image source t.content.querySelector('img').src = 'logo.png'; // clone and append document fragment document.body.appendChild(t.content.cloneNode(true));
You can activate templates by cloning their content document fragment.
HTML Templates - Inert chunks of clonable DOM
Shadow DOM - Style & DOM encapsulation
Custom Elements - Define and use new DOM elements
HTML Imports - Include other HTML documents
HTML Templates - Inert chunks of clonable DOM
Shadow DOM - Style & DOM encapsulation
Custom Elements - Define and use new DOM elements
HTML Imports - Include other HTML documents
Shadow DOM gives us DOM tree encapsulation and style boundaries.
.createShadowRoot() creates a shadow root on a host element.
<div>Hello World!</div>
var host = document.querySelector('div'); var shadowRoot = host.createShadowRoot(); shadowRoot.innerHTML = 'Hello ngEurope!';
Simply combine the things we just learned.
var host = document.querySelector('#host'); var shadowRoot = host.createShadowRoot(); var t = document.querySelector('#custom-template'); shadowRoot.appendChild(t.content.cloneNode(true));
HTML Templates - Inert chunks of clonable DOM
Shadow DOM - Style & DOM encapsulation
Custom Elements - Define and use new DOM elements
HTML Imports - Include other HTML documents
HTML Templates - Inert chunks of clonable DOM
Shadow DOM - Style & DOM encapsulation
Custom Elements - Define and use new DOM elements
HTML Imports - Include other HTML documents
Custom Elements allow web developers to define new types of HTML elements.
document.registerElement('custom-element', { prototype: Proto });
document.registerElement() let's you register custom elements.
- name must contain a dashvar Proto = Object.create(HTMLElement); Proto.fooProperty = 'bar'; Proto.createdCallback = function () { /* e.g. create shadow root */ }; Proto.attributeChangedCallback = function (name, old, new) { /* ... */ };
var myElement = document.createElement('custom-element'); document.appendChild(myElement);
HTML Templates - Inert chunks of clonable DOM
Shadow DOM - Style & DOM encapsulation
Custom Elements - Define and use new DOM elements
HTML Imports - Include other HTML documents
HTML Templates - Inert chunks of clonable DOM
Shadow DOM - Style & DOM encapsulation
Custom Elements - Define and use new DOM elements
HTML Imports - Include other HTML documents
<link rel="import" href="path/to/import.html">
Use <link rel="import"> to import external HTML documents.
var link = document.querySelector('link[rel="import"]'); var content = link.import; var el = content.querySelector('.widget'); document.body.appendChild(el);
The imports .import property can be used to query DOM objects.
Could look like this...
...or like this:
Angular doesn't know and shouldn't know about custom elements.
So how do custom elements actually notify the outside world?
A custom element can change DOM attributes or Element properties.
Everything in this section is based on wip documents. Things might change in the future.
(Do not try this at home!)
So how does Angular 2.0 tackle the existing issues in the future?
var ngDuoProto = Object.create(HTMLElement.prototype, { // Element properties sources: { get: function() {...}, set: function(value) {...} } });
The syntax proposal for property binding is "[ ]"
One syntax proposal is to wrap event names in "( )"
By Carmen Popoviciu and Pascal Precht a.k.a ng-duo