144
Creating container components in Web Components and Angular ng-conf: March 5, 2015 Kara Erickson Web Engineer kara karaforthewin Rachael L Moore UI Engineer morewry morewry

Creating GUI container components in Angular and Web Components

Embed Size (px)

Citation preview

Page 1: Creating GUI container components in Angular and Web Components

Creating containercomponentsin Web Components and Angularng-conf: March 5, 2015

Kara EricksonWeb Engineer kara karaforthewin

Rachael L MooreUI Engineer morewry morewry

Page 2: Creating GUI container components in Angular and Web Components

Roadmap

Web Components

Angular 1.3

Angular 2.0

Page 3: Creating GUI container components in Angular and Web Components
Page 4: Creating GUI container components in Angular and Web Components
Page 5: Creating GUI container components in Angular and Web Components

<!-- #include virtual="head.html" -->

<!-- #include virtual="menu.html" -->

I render in body.

<!-- #include virtual="foot.html" -->

Server Side Includes

Page 6: Creating GUI container components in Angular and Web Components

{{> head}}

{{> menu}}

I render in body.

{{> foot}}

mustache

Page 7: Creating GUI container components in Angular and Web Components

UI Components

<ot-site>

I render in body.

</ot-site>

Page 8: Creating GUI container components in Angular and Web Components

Native Elements

<input type="range" />

<input type="range" min="1"

max="8" />

Page 9: Creating GUI container components in Angular and Web Components
Page 10: Creating GUI container components in Angular and Web Components
Page 11: Creating GUI container components in Angular and Web Components

<div id="site">

</div>

Component Development

Page 12: Creating GUI container components in Angular and Web Components

<div id="site">

<header></header>

</div>

Head   

Component Development

Page 13: Creating GUI container components in Angular and Web Components

<div id="site">

<header></header>

<nav></nav>>

</div>

Component Development

Menu   

Page 14: Creating GUI container components in Angular and Web Components

<div id="site">

<header></header>

<nav></nav>

<main></main>

</div>

Component Development

Body   

Page 15: Creating GUI container components in Angular and Web Components

<div id="site">

<header></header>

<nav></nav>

<main></main>

</div>

Component Development

Page 16: Creating GUI container components in Angular and Web Components

<div id="site">

<header>

<svg id="logo"></svg>

</header>

<nav></nav>

<main></main>

</div>

Component Development

Body   

Page 17: Creating GUI container components in Angular and Web Components

<div id="site">

<header>

<svg id="logo"></svg>

</header>

<nav></nav>

<main></main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>

Component Development

Page 18: Creating GUI container components in Angular and Web Components

<div id="site">

<header>

<svg id="logo"></svg>

</header>

<nav></nav>

<main></main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>

Component Development

Page 19: Creating GUI container components in Angular and Web Components

<div id="site">

<header>

<svg id="logo"></svg>

<!-- point-1 -->

</header>

<nav>

<!-- point-2 -->

</nav>

<main>

<!-- point-3 -->

</main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>

Component Development

Page 20: Creating GUI container components in Angular and Web Components

Component Use

<ot-site>

</ot-site>

Page 21: Creating GUI container components in Angular and Web Components

Component Use

<ot-site>

<div>

I render in head.

</div>

<div>

I render in menu.

</div>

<div>

I render in body.

</div>

</ot-site>

I render in head.

I render in menu.

I render in body.

Page 22: Creating GUI container components in Angular and Web Components

Component Use

<ot-site>

<div>

<!-- insert-1 -->

I render in head.

</div>

<div>

<!-- insert-2 -->

I render in menu.

</div>

<div>

<!-- insert-3 -->

I render in body.

</div>

</ot-site>

I render in head.

I render in menu.

I render in body.

Page 23: Creating GUI container components in Angular and Web Components

<div id="site">

<header>

<svg id="logo"></svg>

<!-- point-1 -->

</header>

<nav>

<!-- point-2 -->

</nav>

<main>

<!-- point-3 -->

</main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>

<ot-site>

<div>

<!-- insert-1 -->

I render in head.

</div>

<div>

<!-- insert-2 -->

I render in menu.

</div>

<div>

<!-- insert-3 -->

I render in body.

</div>

</ot-site>

Match Content → ← Match Component

Page 24: Creating GUI container components in Angular and Web Components
Page 25: Creating GUI container components in Angular and Web Components

Head   

Page 26: Creating GUI container components in Angular and Web Components

Menu   

Page 27: Creating GUI container components in Angular and Web Components

Body   

Page 28: Creating GUI container components in Angular and Web Components

Web Components

Shadow DOM

<ot-site>

Page 29: Creating GUI container components in Angular and Web Components

Native Elements

<input type="range" />

Page 30: Creating GUI container components in Angular and Web Components

Secrets and Shadows

Page 31: Creating GUI container components in Angular and Web Components
Page 32: Creating GUI container components in Angular and Web Components

Shadow DOM

Page 33: Creating GUI container components in Angular and Web Components

Light DOM

Shadow DOM

Page 34: Creating GUI container components in Angular and Web Components

Light DOM

<input type="range" />

Page 35: Creating GUI container components in Angular and Web Components

<input type="range" />

#shadow-root (user-agent)

<div pseudo="track" id="track">

<div pseudo="thumb" id="thumb">

</div>

</div>

UA Shadow DOM

Page 36: Creating GUI container components in Angular and Web Components

...had flourished.

<span id="myspan">

Long ago there was something in me, but now that thing is gone.

</span>

I cannot...

Shadow Host

Page 37: Creating GUI container components in Angular and Web Components

var $ = document.querySelector.bind(document)

var span = $("#myspan")

span.createShadowRoot()

Shadow Root

Page 38: Creating GUI container components in Angular and Web Components

...had flourished.

<span id="myspan">

Long ago there was something in me, but now that thing is gone.

</span>

I cannot...

Shadow Host

Page 39: Creating GUI container components in Angular and Web Components

...had flourished.

<span id="myspan">

#shadow-root

Long ago there was something in me, but now that thing is gone.

</span>

I cannot...

Shadow Root

Page 40: Creating GUI container components in Angular and Web Components

Before

...had flourished. Long

ago there was something

in me, but now that thing

is gone. I cannot...

After

...had flourished. I

cannot...

Page 41: Creating GUI container components in Angular and Web Components

var host = $("ot-site")

host.createShadowRoot()

host.shadowRoot.innerHTML = ``

ot-site.js

Page 42: Creating GUI container components in Angular and Web Components

host.shadowRoot.innerHTML = .``.

ot-site.js

Page 43: Creating GUI container components in Angular and Web Components

host.shadowRoot.innerHTML = `

<div id="site">

<header>

<svg id="logo"></svg>

<!-- point-1 -->

</header>

<nav>

<!-- point-2 -->

</nav>

<main>

<!-- point-3 -->

</main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>

`ot-site.js

Page 44: Creating GUI container components in Angular and Web Components

host.shadowRoot.innerHTML = `

<div id="site">

<header>

<svg id="logo"></svg>

<!-- point-1 -->

</header>

<nav>

<!-- point-2 -->

</nav>

<main>

<!-- point-3 -->

</main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>

`ot-site.js

Page 45: Creating GUI container components in Angular and Web Components

host.shadowRoot.innerHTML += `

<style>

/* use your imagination */

</style>

`

ot-site.js

Page 46: Creating GUI container components in Angular and Web Components

<ot-site>

#shadow-root

<div id="site">

<header>

<svg id="logo"></svg>

</header>

<nav></nav>

<main></main>

<footer>©</footer>

</div>

<style>/**/</style>

</ot-site>

Composed DOM

Page 47: Creating GUI container components in Angular and Web Components
Page 48: Creating GUI container components in Angular and Web Components

host.shadowRoot.innerHTML = `

<div id="site">

<header>

<svg id="logo"></svg>

<!-- point-1 -->

</header>

<nav>

<!-- point-2 -->

</nav>

<main>

<!-- point-3 -->

</main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>

`ot-site.js

Page 49: Creating GUI container components in Angular and Web Components

host.shadowRoot.innerHTML = `

<div id="site">

<header>

<svg id="logo"></svg>

<content />

</header>

<nav>

<content />

</nav>

<main>

<content />

</main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>

`ot-site.js

Page 50: Creating GUI container components in Angular and Web Components

host.shadowRoot.innerHTML = `

<div id="site">

<header>

<svg id="logo"></svg>

<content select="" />

</header>

<nav>

<content select="" />

</nav>

<main>

<content select="" />

</main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>

`ot-site.js

Page 51: Creating GUI container components in Angular and Web Components

host.shadowRoot.innerHTML = `

<div id="site">

<header>

<svg id="logo"></svg>

<content select="[head]" />

</header>

<nav>

<content select="[menu]" />

</nav>

<main>

<content select="[body]" />

</main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>

`ot-site.js

Page 52: Creating GUI container components in Angular and Web Components

<ot-site>

<div>

<!-- insert-1 -->

I render in head.

</div>

<div>

<!-- insert-2 -->

I render in menu.

</div>

<div>

<!-- insert-3 -->

I render in body.

</div>

</ot-site>

index.html

Page 53: Creating GUI container components in Angular and Web Components

<ot-site>

<div head>

I render in head.

</div>

<div menu>

I render in menu.

</div>

<div body>

I render in body.

</div>

</ot-site>

index.html

Page 54: Creating GUI container components in Angular and Web Components

Match Content →

<div id="site">

<header>

<svg id="logo"></svg>

<content select="[head]"/>

</header>

<nav>

<content select="[menu]"/>

</nav>

<main>

<content select="[body]"/>

</main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>

<ot-site>

<div head>

I render in head.

</div>

<div menu>

I render in menu.

</div>

<div body>

I render in body.

</div>

</ot-site>

← Match Component

Page 55: Creating GUI container components in Angular and Web Components

Light DOMShadow DOM

<div id="site">

  <header>

    <svg id="logo"></svg>

    <content select="[head]"/>

</header>

<nav>

<content� select="[menu]"/>

</nav>

<main>

<content select="[body]"/>

</main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>

<ot-site>

<div head>

I render in head.

</div>

<div menu>

I render in menu.

</div>

<div body>

I render in body.

</div>

</ot-site>

Page 56: Creating GUI container components in Angular and Web Components
Page 57: Creating GUI container components in Angular and Web Components

<div id="site">

<header>

<svg id="logo"></svg>

<content select="[head]"/>

</header>

<nav>

<content select="[menu]"/>

</nav>

<main>

<content select="[body]"/>

</main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>

Light DOMShadow DOM

<ot-site>

<div head>

I render in head.

</div>

<div menu>

I render in menu.

</div>

<div body>

I render in body.

</div>

</ot-site>

Page 58: Creating GUI container components in Angular and Web Components

I render in head.

I render in menu.

I render in body.

Page 59: Creating GUI container components in Angular and Web Components

I render in head.

I render in menu.

I render in body.

Page 62: Creating GUI container components in Angular and Web Components

Angular 1.3

Transcluding Directive

<ot-site>

Page 63: Creating GUI container components in Angular and Web Components

.directive("otSite", function() { return { template: `` };});

ot-site.js

Page 64: Creating GUI container components in Angular and Web Components

.directive("otSite", function() { return { template: ` <div id="site"> <header> <!-- point-1 -->

<svg id="logo"></svg>

</header>

<nav></nav> <!-- point-2 -->

<main></main> <!-- point-3 -->

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>`

};

});

ot-site.js

Page 65: Creating GUI container components in Angular and Web Components
Page 66: Creating GUI container components in Angular and Web Components

Transclusion

Page 67: Creating GUI container components in Angular and Web Components

<ot-site>

</ot-site>

index.html

Page 68: Creating GUI container components in Angular and Web Components

<ot-site>

<div>

I render in head.

</div>

<div>

I render in menu.

</div>

<div>

I render in body.

</div>

</ot-site>

index.html

Page 69: Creating GUI container components in Angular and Web Components

<ot-site>

<div>

I render in head.

</div>

<div>

I render in menu.

</div>

<div>

I render in body.

</div>

</ot-site>

index.html

Page 70: Creating GUI container components in Angular and Web Components

ot-site.js

.directive("otSite", function() { return { template: `

<div id="site"> <header>

<svg id="logo"></svg>

</header>

<nav></nav>

<main></main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>`

};

});

Page 71: Creating GUI container components in Angular and Web Components

ot-site.js

.directive("otSite", function() { return { transclude: true, template: `

<div id="site"> <header>

<svg id="logo"></svg>

</header>

<nav></nav>

<main></main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>`

};

});

Page 72: Creating GUI container components in Angular and Web Components

<ot-site>

<div>

I render in head.

</div>

<div>

I render in menu.

</div>

<div>

I render in body.

</div>

</ot-site>

DOM

Page 73: Creating GUI container components in Angular and Web Components

<ot-site>

<div>

I render in head.

</div>

<div>

I render in menu.

</div>

<div>

I render in body.

</div>

</ot-site>

DOM

Page 74: Creating GUI container components in Angular and Web Components

DOM

<ot-site>

<div id="site">

<header>

<svg id="logo"></svg>

</header>

<nav></nav>

<main></main>

<footer>©</footer>

</div>

</ot-site>

Page 75: Creating GUI container components in Angular and Web Components

<ot-site>

<div>

I render in head.

</div>

<div>

I render in menu.

</div>

<div>

I render in body.

</div>

</ot-site>

DOM

Page 76: Creating GUI container components in Angular and Web Components

<ot-site>

<div>

I render in head.

</div>

<div>

I render in menu.

</div>

<div>

I render in body.

</div>

</ot-site>

Clone DOM

Page 77: Creating GUI container components in Angular and Web Components

<ot-site>

<div>

I render in head.

</div>

<div>

I render in menu.

</div>

<div>

I render in body.

</div>

</ot-site>

Clone DOM

Page 78: Creating GUI container components in Angular and Web Components

Clone DOM

<div>

I render in head.

</div>

<div>

I render in menu.

</div>

<div>

I render in body.

</div>

<ot-site>

<div>

I render in head.

</div>

<div>

I render in menu.

</div>

<div>

I render in body.

</div>

</ot-site>

Page 79: Creating GUI container components in Angular and Web Components

<div>

I render in head.

</div>

<div>

I render in menu.

</div>

<div>

I render in body.

</div>

<ot-site>

</ot-site>

Clone DOM

Page 80: Creating GUI container components in Angular and Web Components

<ot-site>

<div id="site">

<header>

<svg id="logo"></svg>

</header>

<nav></nav>

<main></main>

<footer>©</footer>

</div>

</ot-site>

Clone

<div>

I render in head.

</div>

<div>

I render in menu.

</div>

<div>

I render in body.

</div>

DOM

Page 81: Creating GUI container components in Angular and Web Components

ot-site.js

.directive("otSite", function() { return { transclude: true, template: `

<div id="site"> <header>

<svg id="logo"></svg>

</header>

<nav></nav>

<main></main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>`

};

});

Page 82: Creating GUI container components in Angular and Web Components

ot-site.js

.directive("otSite", function() { return { transclude: true, template: `

<div id="site"> <header ng-transclude>

<svg id="logo"></svg>

</header>

<nav ng-transclude></nav>

<main ng-transclude></main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>`

};

});

Page 84: Creating GUI container components in Angular and Web Components

ot-site.js

.directive("otSite", function() { return { transclude: true, template: `

<div id="site"> <header ng-transclude>

<svg id="logo"></svg>

</header>

<nav ng-transclude></nav>

<main ng-transclude></main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>`

};

});

Page 85: Creating GUI container components in Angular and Web Components

ot-site.js

.directive("otSite", function() { return { transclude: true, template: `

<div id="site"> <header>

<svg id="logo"></svg>

</header>

<nav></nav>

<main></main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>`

};

});

Page 86: Creating GUI container components in Angular and Web Components

ot-site.js

.directive("otSite", function() { return { transclude: true, template: `

<div id="site"> <header t-id="head">

<svg id="logo"></svg>

</header>

<nav t-id="menu"></nav>

<main t-id="body"></main>

<footer>

© 2015 OpenTable, Inc.

</footer>

</div>`

};

});

Page 87: Creating GUI container components in Angular and Web Components

<ot-site>

<div>

<!-- insert-1 -->

I render in head.

</div>

<div>

<!-- insert-2 -->

I render in menu.

</div>

<div>

<!-- insert-3 -->

I render in body.

</div>

</ot-site>

index.html

Page 88: Creating GUI container components in Angular and Web Components

<ot-site>

<div t-to="head">

I render in head.

</div>

<div t-to="menu">

I render in menu.

</div>

<div t-to="body">

I render in body.

</div>

</ot-site>

index.html

Page 89: Creating GUI container components in Angular and Web Components

<div t-to="head">

I render in head.

</div>

<div t-to="menu">

I render in menu.

</div>

<div t-to="body">

I render in body.

</div>

<ot-site>

<div id="site">

<header t-id="head">

<svg id="logo"></svg>

</header>

<nav t-id="menu"></nav>

<main t-id="body"></main>

<footer>©</footer>

</div>

</ot-site>

DOMClone

Page 90: Creating GUI container components in Angular and Web Components

<div t-to="head">

I render in head.

</div>

<div t-to="menu">

I render in menu.

</div>

<div t-to="body">

I render in body.

</div>

<ot-site>

<div id="site">

<header t-id="head">

<svg id="logo"></svg>

</header>

<nav t-id="menu"></nav>

<main t-id="body"></main>

<footer>©</footer>

</div>

</ot-site>

DOMClone

angular.forEach(clone, function(cloneEl) {});

Page 91: Creating GUI container components in Angular and Web Components

<div t-to="head">

I render in head.

</div>

<div t-to="menu">

I render in menu.

</div>

<div t-to="body">

I render in body.

</div>

<ot-site>

<div id="site">

<header t-id="head">

<svg id="logo"></svg>

</header>

<nav t-id="menu"></nav>

<main t-id="body"></main>

<footer>©</footer>

</div>

</ot-site>

DOMClone

angular.forEach(clone, function(cloneEl) {});

Page 92: Creating GUI container components in Angular and Web Components

<div t-to="head">

I render in head.

</div>

<div t-to="menu">

I render in menu.

</div>

<div t-to="body">

I render in body.

</div>

<ot-site>

<div id="site">

<header t-id="head">

<svg id="logo"></svg>

</header>

<nav t-id="menu"></nav>

<main t-id="body"></main>

<footer>©</footer>

</div>

</ot-site>

DOMClone

angular.forEach(clone, function(cloneEl) {});

Page 93: Creating GUI container components in Angular and Web Components

<ot-site>

<div id="site">

<header t-id="head">

<svg id="logo"></svg>

</header>

<nav t-id="menu"></nav>

<main t-id="body"></main>

<footer>©</footer>

</div>

</ot-site>

DOMClone

var tId = cloneEl.attributes["t-to"].value;

<div t-to="head">

I render in head.

</div>

<div t-to="menu">

I render in menu.

</div>

<div t-to="body">

I render in body.

</div>

Page 94: Creating GUI container components in Angular and Web Components

DOMClone

var target = temp.find('[t-id="'+tId+'"]');

<div t-to="head">

I render in head.

</div>

<div t-to="menu">

I render in menu.

</div>

<div t-to="body">

I render in body.

</div>

<ot-site>

<div id="site">

<header t-id="head">

<svg id="logo"></svg>

</header>

<nav t-id="menu"></nav>

<main t-id="body"></main>

<footer>©</footer>

</div>

</ot-site>

Page 95: Creating GUI container components in Angular and Web Components

<ot-site>

<div id="site">

<header t-id="head">

<svg id="logo"></svg>

</header>

<nav t-id="menu"></nav>

<main t-id="body"></main>

<footer>©</footer>

</div>

</ot-site>

<div t-to="head">

I render in head.

</div>

<div t-to="menu">

I render in menu.

</div>

<div t-to="body">

I render in body.

</div>

DOMClone

target.append(clone);

Page 96: Creating GUI container components in Angular and Web Components

<div t-to="head">

I render in head.

</div>

<div t-to="menu">

I render in menu.

</div>

<div t-to="body">

I render in body.

</div>

DOMClone

<ot-site>

<div id="site">

<header t-id="head">

<svg id="logo"></svg>

<div t-to="head">

I render in head.

</div>

</header>

<nav t-id="menu"></nav>

<main t-id="body"></main>

<footer>©</footer>

</div>

</ot-site>

</ot-site> target.append(clone);

Page 97: Creating GUI container components in Angular and Web Components

angular.forEach(clone, function(cloneEl) {

// get desired target ID

var tId = cloneEl.attributes["t-to"].value;

// find target element with that ID

var target = temp.find('[t-id="'+tId+'"]');

// append element to target

target.append(cloneEl);

});

custom-transclude.js

Page 98: Creating GUI container components in Angular and Web Components

Transclude functiontransclude(function(clone) {

# DOM manipulation

});

Page 99: Creating GUI container components in Angular and Web Components

Transclude function access pointscompile: function(tElem, tAttrs, transclude)

controller: function($scope, $element, $transclude)

link: function(scope, iElem, iAttrs, ctrl, transclude)

Page 100: Creating GUI container components in Angular and Web Components

compile: function(tElem, tAttrs, transclude)

controller: function($scope, $element, $transclude)

link: function(scope, iElem, iAttrs, ctrl, transclude)

Transclude function access points

Page 101: Creating GUI container components in Angular and Web Components

compile: function(tElem, tAttrs, transclude)

controller: function($scope, $element, $transclude)

link: function(scope, iElem, iAttrs, ctrl, transclude)

Transclude function access points

Page 102: Creating GUI container components in Angular and Web Components

Directive Life Cycle

1

2

3

4

5

6

7

8

Child compile

Child controller

Child pre-link

Child post-link

Parent compile

Parent controller

Parent pre-link

Parent post-link

Page 103: Creating GUI container components in Angular and Web Components

Directive Life Cycle

1

2

3

4

5

6

7

8

Child compile

Child controller

Child pre-link

Child post-link

Parent compile

Parent controller

Parent pre-link

Parent post-link

Page 104: Creating GUI container components in Angular and Web Components

Transclude function availabilitycompile: function(tElem, tAttrs, transclude)

controller: function($scope, $element, $transclude)

link: function(scope, iElem, iAttrs, ctrl, transclude)

Page 105: Creating GUI container components in Angular and Web Components

ot-site.js

.directive("otSite", function() { return {

transclude: true,

template: ...,

link: function(scope, elem, attr, ctrl, transclude) {

}

};

});

Page 106: Creating GUI container components in Angular and Web Components

ot-site.js

.directive("otSite", function() { return {

transclude: true,

template: ...,

link: function(scope, elem, attr, ctrl, transclude) {

transclude(function(clone) {

angular.forEach(clone, function(cloneEl) {

var tId = ...

var target = ...

if (target.length) {...}

else {...}

});

});

}

};

});

Page 107: Creating GUI container components in Angular and Web Components

ot-site.js

.directive("otSite", function() { return {

scope: {},

transclude: true,

template: ...,

link: function(scope, elem, attr, ctrl, transclude) {

transclude(function(clone) {

angular.forEach(clone, function(cloneEl) {

var tId = ...

var target = ...

if (target.length) {...}

else {...}

});

});

}

};

});

Page 108: Creating GUI container components in Angular and Web Components

transcluding directive with isolate scope

Page 109: Creating GUI container components in Angular and Web Components

ot-site.js

.directive("otSite", function() { return {

scope: {},

transclude: true,

template: ...,

link: function(scope, elem, attr, ctrl, transclude) {

transclude(function(clone) {

angular.forEach(clone, function(cloneEl) {

var tId = ...

var target = ...

if (target.length) {...}

else {...}

});

});

}

};

});

Page 111: Creating GUI container components in Angular and Web Components

Angular 2.0

Component Directive

<ot-site>

Page 112: Creating GUI container components in Angular and Web Components

Angular 1.3

Transclusion

Angular 2.0

Page 113: Creating GUI container components in Angular and Web Components

Shadow DOM

Angular 2.0Angular 1.3

Transclusion

Page 114: Creating GUI container components in Angular and Web Components

<div id="site"><header t-id="head">

<svg id="logo"></svg>

</header>

<nav t-id="menu"></nav>

<main t-id="body"></main>

<footer> © 2015 OpenTable, Inc. </footer>

</div>

ot-site template

Page 115: Creating GUI container components in Angular and Web Components

<div id="site"><header t-id="head">

<svg id="logo"></svg>

</header>

<nav t-id="menu"></nav>

<main t-id="body"></main>

<footer> © 2015 OpenTable, Inc. </footer>

</div>

ot-site template

Page 116: Creating GUI container components in Angular and Web Components

<div id="site"><header>

<svg id="logo"></svg>

</header>

<nav></nav>

<main></main>

<footer> © 2015 OpenTable, Inc. </footer>

</div>

ot-site template

Page 117: Creating GUI container components in Angular and Web Components

<div id="site"><header>

<svg id="logo"></svg>

<content select="[head]"></content>

</header>

<nav>

<content select="[menu]"></content>

</nav>

<main>

<content select="[body]"></content>

</main>

<footer> © 2015 OpenTable, Inc. </footer>

</div>

ot-site template

Page 118: Creating GUI container components in Angular and Web Components

ot-site.js

.directive("otSite", function() { return {

scope: {},

transclude: true,

template: ...,

link: function(scope, elem, attr, ctrl, transclude) {

transclude(function(clone) {

angular.forEach(clone, function(cloneEl) {

var tId = ...

var target = ...

if (target.length) {...}

else {...}

});

});

}

};

});

Page 119: Creating GUI container components in Angular and Web Components

ot-site.js

.directive("otSite", function() { return {

scope: {},

transclude: true,

template: ...,

link: function(scope, elem, attr, ctrl, transclude) {

transclude(function(clone) {

angular.forEach(clone, function(cloneEl) {

var tId = ...

var target = ...

if (target.length) {...}

else {...}

});

});

}

};

});

Page 120: Creating GUI container components in Angular and Web Components

ot-site.js

.directive("otSite", function() { return {

scope: {},

transclude: true,

template: ...,

link: function(scope, elem, attr, ctrl, transclude) {

transclude(function(clone) {

angular.forEach(clone, function(cloneEl) {

var tId = ...

var target = ...

if (target.length) {...}

else {...}

});

});

}

};

});

Page 121: Creating GUI container components in Angular and Web Components

Shadow DOM

Angular 2.0Angular 1.3

Transclusion

Manual scope

Page 122: Creating GUI container components in Angular and Web Components

proper transclusion scope

Page 123: Creating GUI container components in Angular and Web Components

Transclusion

Manual scope

Shadow DOM

Sensible default context

Angular 2.0Angular 1.3

Page 124: Creating GUI container components in Angular and Web Components

ot-site.js

.directive("otSite", function() { return {

scope: {},

transclude: true,

template: ...,

link: function(scope, elem, attr, ctrl, transclude) {

transclude(function(clone) {

angular.forEach(clone, function(cloneEl) {

var tId = ...

var target = ...

if (target.length) {...}

else {...}

});

});

}

};

});

Page 125: Creating GUI container components in Angular and Web Components

ot-site.js

.directive("otSite", function() { return {

scope: {},

transclude: true,

template: ...,

link: function(scope, elem, attr, ctrl, transclude) {

transclude(function(clone) {

angular.forEach(clone, function(cloneEl) {

var tId = ...

var target = ...

if (target.length) {...}

else {...}

});

});

}

};

});

Page 126: Creating GUI container components in Angular and Web Components

ot-site.js

.directive("otSite", function() { return {

template: ...

};

});

Page 127: Creating GUI container components in Angular and Web Components

.directive(."otSite"., function() { return {

template: ...

};

});

ot-site.js

Page 128: Creating GUI container components in Angular and Web Components

ot-site.js

.directive(."otSite"., function() { return {

.template: ....

};

});

Page 129: Creating GUI container components in Angular and Web Components

Shadow DOM

Sensible default context

Angular 2.0Angular 1.3

Transclusion

Manual scope

One DDO

Page 130: Creating GUI container components in Angular and Web Components

ot-site.js

.directive("otSite", function() { return {

scope: {},

transclude: true,

template: ...,

link: function(scope, elem, attr, ctrl, transclude) {

transclude(function(clone) {

angular.forEach(clone, function(cloneEl) {

var tId = ...

var target = ...

if (target.length) {...}

else {...}

});

});

}

};

});

Page 131: Creating GUI container components in Angular and Web Components

Shadow DOM

Sensible default context

Class & annotation

Angular 2.0Angular 1.3

Transclusion

Manual scope

One DDO

Page 132: Creating GUI container components in Angular and Web Components

class OtSite() { constructor () {

}

// public methods here

}

ot-site.js

Page 133: Creating GUI container components in Angular and Web Components

ot-site.js

class OtSite() { constructor () {

}

// public methods here

}

OtSite.annotations = [

];

Page 134: Creating GUI container components in Angular and Web Components

ot-site.js

class OtSite() { constructor () {

}

// public methods here

}

OtSite.annotations = [

new Component({

})

];

Page 135: Creating GUI container components in Angular and Web Components

ot-site.js

class OtSite() { constructor () {

}

// public methods here

}

OtSite.annotations = [

new Component({

selector: "ot-site"

})

];

Page 136: Creating GUI container components in Angular and Web Components

ot-site.js

class OtSite() { constructor () {

}

// public methods here

}

OtSite.annotations = [

new Component({

selector: "ot-site"

}),

new Template({

url: "ot-site.html"

})

];

Page 137: Creating GUI container components in Angular and Web Components

ot-site.js

class OtSite() { constructor () {

}

// public methods here

}

OtSite.annotations = [

new Component({

selector: "ot-site"

}),

new Template({

url: "ot-site.html"

})

];

Page 138: Creating GUI container components in Angular and Web Components

ot-site.js

class OtSite() { constructor () {

}

// public methods here

}

@Component({

selector: "ot-site"

})

@Template({

url: "ot-site.html"

})

Page 139: Creating GUI container components in Angular and Web Components

class OtSite() { constructor () {

}

// public methods here

}

@Component({

selector: "ot-site"

})

@Template({

url: "ot-site.html"

})

ot-site.js

Page 140: Creating GUI container components in Angular and Web Components

@Component({

selector: "ot-site"

})

@Template({

url: "ot-site.html"

})

class OtSite() { constructor () {

}

// public methods here

}

ot-site.js

Page 141: Creating GUI container components in Angular and Web Components

ot-site.js

@Component({

selector: "ot-site"

})

@Template({

url: "ot-site.html"

})

class OtSite() { constructor () {

}

// public methods here

}

Page 142: Creating GUI container components in Angular and Web Components

<ot-site>

<div head>

I render in head.

</div>

<div menu>

I render in menu.

</div>

<div body>

I render in body.

</div>

</ot-site>

Page 143: Creating GUI container components in Angular and Web Components

Thanks, everyone!

Kara EricksonWeb Engineer kara karaforthewin

Rachael L MooreUI Engineer morewry morewry

Page 144: Creating GUI container components in Angular and Web Components

We’re hiring!Visit our careers page atopentable.com/careers/

We’re hiring!Visit our careers page atopentable.com/careers/