vs stencil-js
Bo Vandersteene
@reibo_bo
Rob Wormald, Angular Team
Angular-connect 2017
Angular on the inside, standards on the outside
@Inputs = properties
@hostbinding = attributes
@outputs = events
Lifecycle hooks
@Component({
selector: 'qone-top-nav',
templateUrl: './top-nav.component.html'
styleUrls: ['./top-nav.component.scss']
})
export class TopNavComponent implements OnInit {
@Input()
title: string;
_links: Array<string>;
@Output()
open = new EventEmitter<string>();
constructor() {
}
ngOnInit() {
}
@Input()
set links(links: string) {
this._links = links.split(',');
}
}
@NgModule({
imports: [
BrowserModule,
CommonModule
],
declarations: [TopNavComponent],
entryComponents: [TopNavComponent],
})
export class TopNavModule {
ngDoBootstrap() {
}
}
import 'zone.js/dist/zone';
import { platformBrowser } from '@angular/platform-browser';
import { TopNavModuleNgFactory } from './top-nav/top-nav.module.ngfactory';
import { createCustomElement } from '@angular/elements';
import { TopNavComponent } from './top-nav/top-nav.component';
platformBrowser()
.bootstrapModuleFactory(TopNavModuleNgFactory)
.then(({ injector }) => {
const topNamCopmonent = createCustomElement(TopNavComponent, {injector})
customElements.define('qone-top-nav', topNavComponent);
});
import 'zone.js/dist/zone';
import { platformBrowser } from '@angular/platform-browser';
import { TopNavModuleNgFactory } from './top-nav/top-nav.module.ngfactory';
import { createCustomElement } from '@angular/elements';
import { TopNavComponent } from './top-nav/top-nav.component';
platformBrowser()
.bootstrapModuleFactory(TopNavModuleNgFactory)
.then(({ injector }) => {
const topNamCopmonent = createCustomElement(TopNavComponent, {injector})
customElements.define('qone-top-nav', topNavComponent);
});
@NgModule(...)
export class TopNavModule {
constructor(private readonly injector: Injector) {
}
ngDoBootstrap() {
customElements.define(
'qone-top-nav',
createCustomElement(TopNavComponent, { injector: this.injector })
);
}
}
import 'zone.js/dist/zone';
import { platformBrowser } from '@angular/platform-browser';
import { TopNavModuleNgFactory } from './top-nav/top-nav.module.ngfactory';
platformBrowser()
.bootstrapModuleFactory(TopNavModuleNgFactory);
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PageElements</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="src/favicon.ico">
</head>
<body>
<qone-top-nav title="Test Angular elements"></qone-top-nav>
<script src="elements/page-elements.bundle.js"></script>
<script>
const topNav = document.querySelector('qone-top-nav');
topNav.addEventListener('open', (data) => {
console.log(`open`, data);
});
const links = ['first link', 'second link', 'another link'];
topNav.setAttribute('links', links.join(','));
</script>
</body>
</html>