From 12eb19fa3c34bb48b28da8bd33d94d7cc0526cf5 Mon Sep 17 00:00:00 2001 From: Filipe Silva Date: Thu, 13 Oct 2016 17:59:00 +0100 Subject: [PATCH] feat(cb-ts-to-js): add es6 examples update docshredder to shred .es6 optimized focus gulp task convert imports and metadate sections add DI section add host and query metadata section add intro fix capitalization and grammar --- gulpfile.js | 11 +- public/docs/_examples/.gitignore | 1 + .../docs/_examples/_boilerplate/package.json | 1 + .../cb-ts-to-js/js-es6-decorators/.babelrc | 6 + .../js-es6-decorators/app/data.service.es6 | 10 + .../hero-di-inject-additional.component.es6 | 50 ++ .../app/hero-di-inject.component.es6 | 22 + .../app/hero-di.component.es6 | 26 + .../app/hero-io.component.es6 | 73 ++ .../app/hero-lifecycle.component.es6 | 27 + .../js-es6-decorators/app/hero.component.es6 | 30 + .../app/heroes-bindings.component.es6 | 42 + .../app/heroes-queries.component.es6 | 88 +++ .../js-es6-decorators/app/main.es6 | 30 + .../js-es6-decorators/example-config.json | 4 + .../cb-ts-to-js/js-es6-decorators/index.html | 51 ++ .../cb-ts-to-js/js-es6-decorators/plnkr.json | 8 + .../_examples/cb-ts-to-js/js-es6/.babelrc | 5 + .../cb-ts-to-js/js-es6/app/data.service.es6 | 13 + .../hero-di-inject-additional.component.es6 | 61 ++ .../js-es6/app/hero-di-inject.component.es6 | 32 + .../js-es6/app/hero-di.component.es6 | 35 + .../js-es6/app/hero-io.component.es6 | 85 ++ .../js-es6/app/hero-lifecycle.component.es6 | 31 + .../cb-ts-to-js/js-es6/app/hero.component.es6 | 37 + .../js-es6/app/heroes-bindings.component.es6 | 48 ++ .../js-es6/app/heroes-queries.component.es6 | 98 +++ .../_examples/cb-ts-to-js/js-es6/app/main.es6 | 30 + .../cb-ts-to-js/js-es6/example-config.json | 4 + .../_examples/cb-ts-to-js/js-es6/index.html | 52 ++ .../_examples/cb-ts-to-js/js-es6/plnkr.json | 8 + .../hero-di-inject-additional.component.js | 7 +- .../js/app/hero-di-inject.component.js | 13 +- .../js/app/hero-di-inline.component.js | 11 +- .../cb-ts-to-js/js/app/hero-di.component.js | 2 + .../cb-ts-to-js/js/app/hero-dsl.component.js | 3 +- .../js/app/hero-lifecycle.component.js | 7 +- .../cb-ts-to-js/js/app/hero.component.js | 7 +- .../docs/_examples/cb-ts-to-js/js/app/main.js | 9 +- .../hero-di-inject-additional.component.ts | 9 +- .../ts/app/hero-di-inject.component.ts | 5 +- .../cb-ts-to-js/ts/app/hero-di.component.ts | 1 + .../ts/app/hero-lifecycle.component.ts | 3 +- .../ts/app/heroes-bindings.component.ts | 11 +- public/docs/_examples/package.json | 5 +- public/docs/js/latest/cookbook/ts-to-js.jade | 741 +++++++++--------- tools/doc-shredder/doc-shredder.js | 2 +- tools/doc-shredder/regionExtractor.js | 1 + 48 files changed, 1440 insertions(+), 416 deletions(-) create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6-decorators/.babelrc create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/data.service.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-di-inject-additional.component.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-di-inject.component.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-di.component.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-io.component.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-lifecycle.component.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero.component.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/heroes-bindings.component.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/heroes-queries.component.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/main.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6-decorators/example-config.json create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6-decorators/index.html create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6-decorators/plnkr.json create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6/.babelrc create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6/app/data.service.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6/app/hero-di-inject-additional.component.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6/app/hero-di-inject.component.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6/app/hero-di.component.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6/app/hero-io.component.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6/app/hero-lifecycle.component.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6/app/hero.component.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6/app/heroes-bindings.component.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6/app/heroes-queries.component.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6/app/main.es6 create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6/example-config.json create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6/index.html create mode 100644 public/docs/_examples/cb-ts-to-js/js-es6/plnkr.json diff --git a/gulpfile.js b/gulpfile.js index d24edb1f16..765dd3e006 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -247,15 +247,16 @@ function findAndRunE2eTests(filter, outputFile) { e2eSpecPaths.forEach(function(specPath) { // get all of the examples under each dir where a pcFilename is found localExamplePaths = getExamplePaths(specPath, true); - // Filter by language - localExamplePaths = localExamplePaths.filter(function (fn) { - return fn.match('/'+lang+'$') != null; - }); + // Filter by example name if (filter) { localExamplePaths = localExamplePaths.filter(function (fn) { return fn.match(filter) != null; }) } + // Filter by language, also supports variations like js-es6 + localExamplePaths = localExamplePaths.filter(function (fn) { + return fn.match('/'+lang+'(?:-[^/]*)?$') != null; + }); localExamplePaths.forEach(function(examplePath) { examplePaths.push(examplePath); }) @@ -1270,7 +1271,7 @@ function apiExamplesWatch(postShredAction) { } function devGuideExamplesWatch(shredOptions, postShredAction, focus) { - var watchPattern = focus ? '**/{' + focus + ',cb-' + focus+ '}/**/*.*' : '**/*.*'; + var watchPattern = focus ? '{' + focus + ',cb-' + focus+ '}/**/*.*' : '**/*.*'; var includePattern = path.join(shredOptions.examplesDir, watchPattern); // removed this version because gulp.watch has the same glob issue that dgeni has. // var excludePattern = '!' + path.join(shredOptions.examplesDir, '**/node_modules/**/*.*'); diff --git a/public/docs/_examples/.gitignore b/public/docs/_examples/.gitignore index b6733dc6ea..b1a1357472 100644 --- a/public/docs/_examples/.gitignore +++ b/public/docs/_examples/.gitignore @@ -11,6 +11,7 @@ wallaby.js _test-output **/ts/**/*.js +**/js-es6*/**/*.js **/ts-snippets/**/*.js *.d.ts diff --git a/public/docs/_examples/_boilerplate/package.json b/public/docs/_examples/_boilerplate/package.json index 3f255fcbd6..bcccdd978a 100644 --- a/public/docs/_examples/_boilerplate/package.json +++ b/public/docs/_examples/_boilerplate/package.json @@ -18,6 +18,7 @@ "build:webpack": "rimraf dist && webpack --config config/webpack.prod.js --bail", "build:cli": "ng build", "build:aot": "ngc -p tsconfig-aot.json && rollup -c rollup-config.js", + "build:babel": "babel app -d app --extensions \".es6\" --source-maps", "copy-dist-files": "node ./copy-dist-files.js", "i18n": "ng-xi18n" }, diff --git a/public/docs/_examples/cb-ts-to-js/js-es6-decorators/.babelrc b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/.babelrc new file mode 100644 index 0000000000..3aaf507508 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/.babelrc @@ -0,0 +1,6 @@ +{ + "presets": [ + "es2015", + "angular2" + ] +} diff --git a/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/data.service.es6 b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/data.service.es6 new file mode 100644 index 0000000000..7e9c7456c6 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/data.service.es6 @@ -0,0 +1,10 @@ +import { Injectable } from '@angular/core'; + +@Injectable() +export class DataService { + constructor() { + } + getHeroName() { + return 'Windstorm'; + } +} diff --git a/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-di-inject-additional.component.es6 b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-di-inject-additional.component.es6 new file mode 100644 index 0000000000..8cd77b51f6 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-di-inject-additional.component.es6 @@ -0,0 +1,50 @@ +import { + Attribute, + Component, + Inject, + Optional, + NgModule +} from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +// #docregion +@Component({ + selector: 'hero-title', + template: ` +

{{titlePrefix}} {{title}}

+ +

{{ msg }}

+ ` +}) +class TitleComponent { + msg = ''; + constructor( + @Inject('titlePrefix') @Optional() titlePrefix, + @Attribute('title') title + ) { + this.titlePrefix = titlePrefix; + this.title = title; + } + + ok() { + this.msg = 'OK!'; + } +} +// #enddocregion + +@Component({ + selector: 'hero-di-inject-additional', + template: ` + ` +}) +class AppComponent { } + +@NgModule({ + imports: [ BrowserModule ], + declarations: [ + AppComponent, + TitleComponent + ], + bootstrap: [ AppComponent ] +}) +export class HeroesDIInjectAdditionalModule { } diff --git a/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-di-inject.component.es6 b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-di-inject.component.es6 new file mode 100644 index 0000000000..3a89867051 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-di-inject.component.es6 @@ -0,0 +1,22 @@ +import { Component, Inject, NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +// #docregion +@Component({ + selector: 'hero-di-inject', + template: `

Hero: {{name}}

` +}) +class HeroComponent { + constructor(@Inject('heroName') name) { + this.name = name; + } +} +// #enddocregion + +@NgModule({ + imports: [ BrowserModule ], + providers: [ { provide: 'heroName', useValue: 'Windstorm' } ], + declarations: [ HeroComponent ], + bootstrap: [ HeroComponent ] +}) +export class HeroesDIInjectModule { } diff --git a/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-di.component.es6 b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-di.component.es6 new file mode 100644 index 0000000000..e8341509a0 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-di.component.es6 @@ -0,0 +1,26 @@ +import { Component, NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +import { DataService } from './data.service'; + +// #docregion +@Component({ + selector: 'hero-di', + template: `

Hero: {{name}}

` +}) + +class HeroComponent { + name; + constructor(dataService: DataService) { + this.name = dataService.getHeroName(); + } +} +// #enddocregion + +@NgModule({ + imports: [ BrowserModule ], + providers: [ DataService ], + declarations: [ HeroComponent ], + bootstrap: [ HeroComponent ] +}) +export class HeroesDIModule { } diff --git a/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-io.component.es6 b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-io.component.es6 new file mode 100644 index 0000000000..2b954b138a --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-io.component.es6 @@ -0,0 +1,73 @@ +import { + Component, + EventEmitter, + Input, + Output, + NgModule +} from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +// #docregion +@Component({ + selector: 'my-confirm', + template: ` + + + ` +}) +class ConfirmComponent { + @Input() okMsg; + @Input('cancelMsg') notOkMsg; + @Output() ok = + new EventEmitter(); + @Output('cancel') notOk = + new EventEmitter(); + + onOkClick() { + this.ok.next(true); + } + onNotOkClick() { + this.notOk.next(true); + } +} +// #enddocregion + + +@Component({ + selector: 'hero-io', + template: ` + + + OK clicked + Cancel clicked + ` +}) +class AppComponent { + okClicked; + cancelClicked; + + onOk() { + this.okClicked = true; + } + onCancel() { + this.cancelClicked = true; + } +} + + +@NgModule({ + imports: [ BrowserModule ], + declarations: [ + AppComponent, + ConfirmComponent + ], + bootstrap: [ AppComponent ] +}) +export class HeroesIOModule { } diff --git a/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-lifecycle.component.es6 b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-lifecycle.component.es6 new file mode 100644 index 0000000000..6a935731b5 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero-lifecycle.component.es6 @@ -0,0 +1,27 @@ +// #docplaster +// #docregion +import { Component, OnInit } from '@angular/core'; +// #enddocregion +import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +@Component({ + selector: 'hero-lifecycle', + template: `

Hero: {{name}}

` +}) +// #docregion +class HeroComponent{ + name; + ngOnInit() { + this.name = 'Windstorm'; + } +} +// #enddocregion + +@NgModule({ + imports: [ BrowserModule ], + declarations: [ HeroComponent ], + bootstrap: [ HeroComponent ] +}) +export class HeroesLifecycleModule { } + diff --git a/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero.component.es6 b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero.component.es6 new file mode 100644 index 0000000000..4b4ba8529d --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/hero.component.es6 @@ -0,0 +1,30 @@ +// #docplaster +// #docregion metadata +import { Component } from '@angular/core'; + +@Component({ + selector: 'hero-view', + template: + '

Hero: {{getName()}}

' +}) +// #docregion appexport +// #docregion class +export class HeroComponent { + title = 'Hero Detail'; + getName() {return 'Windstorm'; } +} +// #enddocregion class +// #enddocregion appexport +// #enddocregion metadata + +import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +@NgModule({ + imports: [ BrowserModule ], + declarations: [ HeroComponent ], + bootstrap: [ HeroComponent ] +}) +export class HeroesModule { } + + diff --git a/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/heroes-bindings.component.es6 b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/heroes-bindings.component.es6 new file mode 100644 index 0000000000..ef959eabbb --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/heroes-bindings.component.es6 @@ -0,0 +1,42 @@ +import { + Component, + HostBinding, + HostListener, + NgModule +} from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +// #docregion +@Component({ + selector: 'heroes-bindings', + template: ` +

+ Tour of Heroes +

+ ` +}) +class HeroesComponent { + @HostBinding() title = 'Tooltip content'; + @HostBinding('class.heading') hClass = true; + active; + + constructor() {} + + @HostListener('click') + clicked() { + this.active = !this.active; + } + + @HostListener('dblclick', ['$event']) + doubleClicked(evt) { + this.active = true; + } +} +// #enddocregion + +@NgModule({ + imports: [ BrowserModule ], + declarations: [ HeroesComponent ], + bootstrap: [ HeroesComponent ] +}) +export class HeroesHostBindingsModule { } diff --git a/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/heroes-queries.component.es6 b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/heroes-queries.component.es6 new file mode 100644 index 0000000000..bc55ccef24 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/heroes-queries.component.es6 @@ -0,0 +1,88 @@ +import { + Component, + ViewChildren, + ContentChild, + QueryList, + Input, + NgModule +} from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +@Component({ + selector: 'active-label', + template: ` + Active + ` +}) +class ActiveLabelComponent { + active; + + activate() { + this.active = true; + } +} + +// #docregion content +@Component({ + selector: 'a-hero', + template: `

+ {{hero.name}} + +

` +}) +class HeroComponent { + @Input() hero; + active; + + @ContentChild(ActiveLabelComponent) + label; + + activate() { + this.active = true; + this.label.activate(); + } +} +// #enddocregion content + + +// #docregion view +@Component({ + selector: 'heroes-queries', + template: ` + + + + + ` +}) +class HeroesQueriesComponent { + heroData = [ + {id: 1, name: 'Windstorm'}, + {id: 2, name: 'Superman'} + ]; + + @ViewChildren(HeroComponent) + heroCmps; + + activate() { + this.heroCmps.forEach( + (cmp) => cmp.activate() + ); + } +} +// #enddocregion view + +@NgModule({ + imports: [ BrowserModule ], + declarations: [ + HeroesQueriesComponent, + HeroComponent, + ActiveLabelComponent + ], + bootstrap: [ HeroesQueriesComponent ] +}) +export class HeroesQueriesModule { } diff --git a/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/main.es6 b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/main.es6 new file mode 100644 index 0000000000..92f5af5e1a --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/app/main.es6 @@ -0,0 +1,30 @@ +/* tslint:disable no-unused-variable */ +// #docregion ng2import +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; +import { + LocationStrategy, + HashLocationStrategy +} from '@angular/common'; +// #enddocregion ng2import + +// #docregion appimport +import { HeroComponent } from './hero.component'; +// #enddocregion appimport + +import { HeroesModule } from './hero.component'; +import { HeroesLifecycleModule } from './hero-lifecycle.component'; +import { HeroesDIModule } from './hero-di.component'; +import { HeroesDIInjectModule } from './hero-di-inject.component'; +import { HeroesDIInjectAdditionalModule } from './hero-di-inject-additional.component'; +import { HeroesIOModule } from './hero-io.component'; +import { HeroesHostBindingsModule } from './heroes-bindings.component'; +import { HeroesQueriesModule } from './heroes-queries.component'; + +platformBrowserDynamic().bootstrapModule(HeroesModule); +platformBrowserDynamic().bootstrapModule(HeroesLifecycleModule); +platformBrowserDynamic().bootstrapModule(HeroesDIModule); +platformBrowserDynamic().bootstrapModule(HeroesDIInjectModule); +platformBrowserDynamic().bootstrapModule(HeroesDIInjectAdditionalModule); +platformBrowserDynamic().bootstrapModule(HeroesIOModule); +platformBrowserDynamic().bootstrapModule(HeroesHostBindingsModule); +platformBrowserDynamic().bootstrapModule(HeroesQueriesModule); diff --git a/public/docs/_examples/cb-ts-to-js/js-es6-decorators/example-config.json b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/example-config.json new file mode 100644 index 0000000000..391bd1a766 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/example-config.json @@ -0,0 +1,4 @@ +{ + "build": "build:babel", + "run": "http-server:e2e" +} \ No newline at end of file diff --git a/public/docs/_examples/cb-ts-to-js/js-es6-decorators/index.html b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/index.html new file mode 100644 index 0000000000..005fe67c31 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/index.html @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + +

TypeScript to JavaScript

+ Classes and Class Metadata
+ Input and Output Metadata
+ Dependency Injection
+ Host and Query Metadata
+ +
+

Classes and Class Metadata

+ Loading hero-view... + Loading hero-lifecycle... + +
+

Input and Output Metadata

+ Loading hero-io... + +
+

Dependency Injection

+ Loading hero-di... + Loading hero-di-inject... + Loading hero-di-inject-additional... + +
+

Host and Query Metadata

+ Loading heroes-bindings... + Loading heroes-queries... + + + diff --git a/public/docs/_examples/cb-ts-to-js/js-es6-decorators/plnkr.json b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/plnkr.json new file mode 100644 index 0000000000..5c7a5acd44 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6-decorators/plnkr.json @@ -0,0 +1,8 @@ +{ + "description": "TypeScript to JavaScript", + "files":[ + "!**/*.d.ts", + "!**/*.js" + ], + "tags":["cookbook"] +} diff --git a/public/docs/_examples/cb-ts-to-js/js-es6/.babelrc b/public/docs/_examples/cb-ts-to-js/js-es6/.babelrc new file mode 100644 index 0000000000..3c078e9f99 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6/.babelrc @@ -0,0 +1,5 @@ +{ + "presets": [ + "es2015" + ] +} diff --git a/public/docs/_examples/cb-ts-to-js/js-es6/app/data.service.es6 b/public/docs/_examples/cb-ts-to-js/js-es6/app/data.service.es6 new file mode 100644 index 0000000000..de023ce5a0 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6/app/data.service.es6 @@ -0,0 +1,13 @@ +import { Injectable } from '@angular/core'; + +export class DataService { + constructor() { + } + getHeroName() { + return 'Windstorm'; + } +} + +DataService.annotations = [ + new Injectable() +]; diff --git a/public/docs/_examples/cb-ts-to-js/js-es6/app/hero-di-inject-additional.component.es6 b/public/docs/_examples/cb-ts-to-js/js-es6/app/hero-di-inject-additional.component.es6 new file mode 100644 index 0000000000..295d305ac4 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6/app/hero-di-inject-additional.component.es6 @@ -0,0 +1,61 @@ +import { + Attribute, + Component, + Inject, + Optional, + NgModule +} from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +// #docregion +class TitleComponent { + constructor(titlePrefix, title) { + this.titlePrefix = titlePrefix; + this.title = title; + this.msg = ''; + } + + ok() { + this.msg = 'OK!'; + } +} + +TitleComponent.annotations = [ + new Component({ + selector: 'hero-title', + template: ` +

{{titlePrefix}} {{title}}

+ +

{{ msg }}

+ ` + }) +]; + +TitleComponent.parameters = [ + [new Optional(), new Inject('titlePrefix')], + [new Attribute('title')] +]; +// #enddocregion + +class AppComponent { +} +AppComponent.annotations = [ + new Component({ + selector: 'hero-di-inject-additional', + template: ` + ` + }) +]; + +export class HeroesDIInjectAdditionalModule { } + +HeroesDIInjectAdditionalModule.annotations = [ + new NgModule({ + imports: [ BrowserModule ], + declarations: [ + AppComponent, + TitleComponent + ], + bootstrap: [ AppComponent ] + }) +]; diff --git a/public/docs/_examples/cb-ts-to-js/js-es6/app/hero-di-inject.component.es6 b/public/docs/_examples/cb-ts-to-js/js-es6/app/hero-di-inject.component.es6 new file mode 100644 index 0000000000..cc8df60abc --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6/app/hero-di-inject.component.es6 @@ -0,0 +1,32 @@ +import { Component, Inject, NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +// #docregion +class HeroComponent { + constructor(name) { + this.name = name; + } +} + +HeroComponent.annotations = [ + new Component({ + selector: 'hero-di-inject', + template: `

Hero: {{name}}

` + }) +]; + +HeroComponent.parameters = [ + [new Inject('heroName')] +]; +// #enddocregion + +export class HeroesDIInjectModule { } + +HeroesDIInjectModule.annotations = [ + new NgModule({ + imports: [ BrowserModule ], + providers: [ { provide: 'heroName', useValue: 'Windstorm' } ], + declarations: [ HeroComponent ], + bootstrap: [ HeroComponent ] + }) +]; diff --git a/public/docs/_examples/cb-ts-to-js/js-es6/app/hero-di.component.es6 b/public/docs/_examples/cb-ts-to-js/js-es6/app/hero-di.component.es6 new file mode 100644 index 0000000000..bb569e6e2b --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6/app/hero-di.component.es6 @@ -0,0 +1,35 @@ +import { Component, NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +import { DataService } from './data.service'; + +// #docregion +class HeroComponent { + constructor(dataService) { + this.name = dataService.getHeroName(); + } +} + +HeroComponent.annotations = [ + new Component({ + selector: 'hero-di', + template: `

Hero: {{name}}

` + }) +]; + +HeroComponent.parameters = [ + [DataService] +]; + +// #enddocregion + +export class HeroesDIModule { } + +HeroesDIModule.annotations = [ + new NgModule({ + imports: [ BrowserModule ], + providers: [ DataService ], + declarations: [ HeroComponent ], + bootstrap: [ HeroComponent ] + }) +]; diff --git a/public/docs/_examples/cb-ts-to-js/js-es6/app/hero-io.component.es6 b/public/docs/_examples/cb-ts-to-js/js-es6/app/hero-io.component.es6 new file mode 100644 index 0000000000..549d75ce7c --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6/app/hero-io.component.es6 @@ -0,0 +1,85 @@ +import { + Component, + EventEmitter, + Input, + Output, + NgModule +} from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +// #docregion +class ConfirmComponent { + constructor(){ + this.ok = new EventEmitter(); + this.notOk = new EventEmitter(); + } + onOkClick() { + this.ok.next(true); + } + onNotOkClick() { + this.notOk.next(true); + } +} + +ConfirmComponent.annotations = [ + new Component({ + selector: 'my-confirm', + template: ` + + + `, + inputs: [ + 'okMsg', + 'notOkMsg: cancelMsg' + ], + outputs: [ + 'ok', + 'notOk: cancel' + ] + }) +]; +// #enddocregion + +class AppComponent { + constructor(){ + } + onOk() { + this.okClicked = true; + } + onCancel() { + this.cancelClicked = true; + } +} + +AppComponent.annotations = [ + new Component({ + selector: 'hero-io', + template: ` + + + OK clicked + Cancel clicked + ` + }) +]; + + +export class HeroesIOModule { } + +HeroesIOModule.annotations = [ + new NgModule({ + imports: [ BrowserModule ], + declarations: [ + AppComponent, + ConfirmComponent + ], + bootstrap: [ AppComponent ] + }) +]; diff --git a/public/docs/_examples/cb-ts-to-js/js-es6/app/hero-lifecycle.component.es6 b/public/docs/_examples/cb-ts-to-js/js-es6/app/hero-lifecycle.component.es6 new file mode 100644 index 0000000000..8a9c6c6c4e --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6/app/hero-lifecycle.component.es6 @@ -0,0 +1,31 @@ +// #docplaster +// #docregion +import { Component } from '@angular/core'; +// #enddocregion +import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +// #docregion +class HeroComponent { + ngOnInit() { + this.name = 'Windstorm'; + } +} +// #enddocregion + +HeroComponent.annotations = [ + new Component({ + selector: 'hero-lifecycle', + template: `

Hero: {{name}}

` + }) +]; + +export class HeroesLifecycleModule { } + +HeroesLifecycleModule.annotations = [ + new NgModule({ + imports: [ BrowserModule ], + declarations: [ HeroComponent ], + bootstrap: [ HeroComponent ] + }) +]; \ No newline at end of file diff --git a/public/docs/_examples/cb-ts-to-js/js-es6/app/hero.component.es6 b/public/docs/_examples/cb-ts-to-js/js-es6/app/hero.component.es6 new file mode 100644 index 0000000000..4b5c20057a --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6/app/hero.component.es6 @@ -0,0 +1,37 @@ +// #docplaster +// #docregion metadata +import { Component } from '@angular/core'; + +// #docregion class +// #docregion appexport +export class HeroComponent { + construct() { + this.title = 'Hero Detail'; + } + getName() {return 'Windstorm'; } +} +// #enddocregion appexport +// #enddocregion class + +HeroComponent.annotations = [ + new Component({ + selector: 'hero-view', + template: '

Hero: {{getName()}}

' + }) +]; +// #enddocregion metadata + +import { NgModule } from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +export class HeroesModule { } + +HeroesModule.annotations = [ + new NgModule({ + imports: [ BrowserModule ], + declarations: [ HeroComponent ], + bootstrap: [ HeroComponent ] + }) +]; + + diff --git a/public/docs/_examples/cb-ts-to-js/js-es6/app/heroes-bindings.component.es6 b/public/docs/_examples/cb-ts-to-js/js-es6/app/heroes-bindings.component.es6 new file mode 100644 index 0000000000..5c13e586a6 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6/app/heroes-bindings.component.es6 @@ -0,0 +1,48 @@ +import { + Component, + HostBinding, + HostListener, + NgModule +} from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +// #docregion +class HeroesComponent { + constructor() { + this.title = 'Tooltip content'; + this.hClass = true; + } + + clicked() { + this.active = !this.active; + } + + doubleClicked(evt) { + this.active = true; + } +} +HeroesComponent.annotations = [ + new Component({ + selector: 'heroes-bindings', + template: `

+ Tour of Heroes +

`, + host: { + '[title]': 'title', + '[class.heading]': 'hClass', + '(click)': 'clicked()', + '(dblclick)': 'doubleClicked($event)' + } + }) +]; +// #enddocregion + +export class HeroesHostBindingsModule { } + +HeroesHostBindingsModule.annotations = [ + new NgModule({ + imports: [ BrowserModule ], + declarations: [ HeroesComponent ], + bootstrap: [ HeroesComponent ] + }) +]; \ No newline at end of file diff --git a/public/docs/_examples/cb-ts-to-js/js-es6/app/heroes-queries.component.es6 b/public/docs/_examples/cb-ts-to-js/js-es6/app/heroes-queries.component.es6 new file mode 100644 index 0000000000..4cec0c3bbd --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6/app/heroes-queries.component.es6 @@ -0,0 +1,98 @@ +import { + Component, + ViewChildren, + ContentChild, + QueryList, + Input, + NgModule +} from '@angular/core'; +import { BrowserModule } from '@angular/platform-browser'; + +class ActiveLabelComponent { + activate() { + this.active = true; + } +} + +ActiveLabelComponent.annotations = [ + new Component({ + selector: 'active-label', + template: ` + + Active + ` + }) +]; + +// #docregion content +class HeroComponent { + activate() { + this.active = true; + this.label.activate(); + } +} + +HeroComponent.annotations = [ + new Component({ + selector: 'a-hero', + template: `

+ {{hero.name}} + +

`, + inputs: ['hero'], + queries: { + label: new ContentChild(ActiveLabelComponent) + } + }) +]; +// #enddocregion content + + +// #docregion view +class HeroesQueriesComponent { + constructor(){ + this.heroData = [ + {id: 1, name: 'Windstorm'}, + {id: 2, name: 'Superman'} + ]; + } + + activate() { + this.heroCmps.forEach( + (cmp) => cmp.activate() + ); + } +} + +HeroesQueriesComponent.annotations = [ + new Component({ + selector: 'heroes-queries', + template: ` + + + + + `, + queries: { + heroCmps: new ViewChildren(HeroComponent) + } + }) +]; +// #enddocregion view + +export class HeroesQueriesModule { } + +HeroesQueriesModule.annotations = [ + new NgModule({ + imports: [ BrowserModule ], + declarations: [ + HeroesQueriesComponent, + HeroComponent, + ActiveLabelComponent + ], + bootstrap: [ HeroesQueriesComponent ] + }) +]; diff --git a/public/docs/_examples/cb-ts-to-js/js-es6/app/main.es6 b/public/docs/_examples/cb-ts-to-js/js-es6/app/main.es6 new file mode 100644 index 0000000000..92f5af5e1a --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6/app/main.es6 @@ -0,0 +1,30 @@ +/* tslint:disable no-unused-variable */ +// #docregion ng2import +import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; +import { + LocationStrategy, + HashLocationStrategy +} from '@angular/common'; +// #enddocregion ng2import + +// #docregion appimport +import { HeroComponent } from './hero.component'; +// #enddocregion appimport + +import { HeroesModule } from './hero.component'; +import { HeroesLifecycleModule } from './hero-lifecycle.component'; +import { HeroesDIModule } from './hero-di.component'; +import { HeroesDIInjectModule } from './hero-di-inject.component'; +import { HeroesDIInjectAdditionalModule } from './hero-di-inject-additional.component'; +import { HeroesIOModule } from './hero-io.component'; +import { HeroesHostBindingsModule } from './heroes-bindings.component'; +import { HeroesQueriesModule } from './heroes-queries.component'; + +platformBrowserDynamic().bootstrapModule(HeroesModule); +platformBrowserDynamic().bootstrapModule(HeroesLifecycleModule); +platformBrowserDynamic().bootstrapModule(HeroesDIModule); +platformBrowserDynamic().bootstrapModule(HeroesDIInjectModule); +platformBrowserDynamic().bootstrapModule(HeroesDIInjectAdditionalModule); +platformBrowserDynamic().bootstrapModule(HeroesIOModule); +platformBrowserDynamic().bootstrapModule(HeroesHostBindingsModule); +platformBrowserDynamic().bootstrapModule(HeroesQueriesModule); diff --git a/public/docs/_examples/cb-ts-to-js/js-es6/example-config.json b/public/docs/_examples/cb-ts-to-js/js-es6/example-config.json new file mode 100644 index 0000000000..391bd1a766 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6/example-config.json @@ -0,0 +1,4 @@ +{ + "build": "build:babel", + "run": "http-server:e2e" +} \ No newline at end of file diff --git a/public/docs/_examples/cb-ts-to-js/js-es6/index.html b/public/docs/_examples/cb-ts-to-js/js-es6/index.html new file mode 100644 index 0000000000..3a8a4e7960 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6/index.html @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + +

TypeScript to JavaScript

+ Classes and Class Metadata
+ Input and Output Metadata
+ Dependency Injection
+ Host and Query Metadata
+ + +
+

Classes and Class Metadata

+ Loading hero-view... + Loading hero-lifecycle... + +
+

Input and Output Metadata

+ Loading hero-io... + +
+

Dependency Injection

+ Loading hero-di... + Loading hero-di-inject... + Loading hero-di-inject-additional... + +
+

Host and Query Metadata

+ Loading heroes-bindings... + Loading heroes-queries... + + + diff --git a/public/docs/_examples/cb-ts-to-js/js-es6/plnkr.json b/public/docs/_examples/cb-ts-to-js/js-es6/plnkr.json new file mode 100644 index 0000000000..5c7a5acd44 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js-es6/plnkr.json @@ -0,0 +1,8 @@ +{ + "description": "TypeScript to JavaScript", + "files":[ + "!**/*.d.ts", + "!**/*.js" + ], + "tags":["cookbook"] +} diff --git a/public/docs/_examples/cb-ts-to-js/js/app/hero-di-inject-additional.component.js b/public/docs/_examples/cb-ts-to-js/js/app/hero-di-inject-additional.component.js index fa9684e7a1..64009317a9 100644 --- a/public/docs/_examples/cb-ts-to-js/js/app/hero-di-inject-additional.component.js +++ b/public/docs/_examples/cb-ts-to-js/js/app/hero-di-inject-additional.component.js @@ -9,10 +9,7 @@ '

{{ msg }}

' }).Class({ constructor: [ - [ - new ng.core.Optional(), - new ng.core.Inject('titlePrefix') - ], + [ new ng.core.Optional(), new ng.core.Inject('titlePrefix') ], new ng.core.Attribute('title'), function(titlePrefix, title) { this.titlePrefix = titlePrefix; @@ -33,7 +30,7 @@ }).Class({ constructor: function() { } }); - + app.HeroesDIInjectAdditionalModule = ng.core.NgModule({ imports: [ ng.platformBrowser.BrowserModule ], diff --git a/public/docs/_examples/cb-ts-to-js/js/app/hero-di-inject.component.js b/public/docs/_examples/cb-ts-to-js/js/app/hero-di-inject.component.js index dfda83e1f0..743af3b987 100644 --- a/public/docs/_examples/cb-ts-to-js/js/app/hero-di-inject.component.js +++ b/public/docs/_examples/cb-ts-to-js/js/app/hero-di-inject.component.js @@ -25,7 +25,7 @@ .Class({ constructor: function() {} }); - + })(window.app = window.app || {}); (function(app) { @@ -35,11 +35,12 @@ template: '

Hero: {{name}}

' }) .Class({ - constructor: - [new ng.core.Inject('heroName'), - function(name) { - this.name = name; - }] + constructor: [ + new ng.core.Inject('heroName'), + function(name) { + this.name = name; + } + ] }); // #enddocregion ctor diff --git a/public/docs/_examples/cb-ts-to-js/js/app/hero-di-inline.component.js b/public/docs/_examples/cb-ts-to-js/js/app/hero-di-inline.component.js index 1fe9c38cb1..e5ef79bc4b 100644 --- a/public/docs/_examples/cb-ts-to-js/js/app/hero-di-inline.component.js +++ b/public/docs/_examples/cb-ts-to-js/js/app/hero-di-inline.component.js @@ -5,11 +5,12 @@ template: '

Hero: {{name}}

' }) .Class({ - constructor: - [app.DataService, - function(service) { - this.name = service.getHeroName(); - }] + constructor: [ + app.DataService, + function(service) { + this.name = service.getHeroName(); + } + ] }); // #enddocregion diff --git a/public/docs/_examples/cb-ts-to-js/js/app/hero-di.component.js b/public/docs/_examples/cb-ts-to-js/js/app/hero-di.component.js index 55c576b836..c4e7d6735e 100644 --- a/public/docs/_examples/cb-ts-to-js/js/app/hero-di.component.js +++ b/public/docs/_examples/cb-ts-to-js/js/app/hero-di.component.js @@ -6,9 +6,11 @@ function HeroComponent(dataService) { this.name = dataService.getHeroName(); } + HeroComponent.parameters = [ app.DataService ]; + HeroComponent.annotations = [ new ng.core.Component({ selector: 'hero-di', diff --git a/public/docs/_examples/cb-ts-to-js/js/app/hero-dsl.component.js b/public/docs/_examples/cb-ts-to-js/js/app/hero-dsl.component.js index 5dd84733f3..a073138cff 100644 --- a/public/docs/_examples/cb-ts-to-js/js/app/hero-dsl.component.js +++ b/public/docs/_examples/cb-ts-to-js/js/app/hero-dsl.component.js @@ -5,8 +5,7 @@ // #docregion component var HeroComponent = ng.core.Component({ selector: 'hero-view-2', - template: - '

Name: {{getName()}}

', + template: '

Name: {{getName()}}

', }) .Class({ constructor: function() { diff --git a/public/docs/_examples/cb-ts-to-js/js/app/hero-lifecycle.component.js b/public/docs/_examples/cb-ts-to-js/js/app/hero-lifecycle.component.js index 3e81c72e4e..1a2028d316 100644 --- a/public/docs/_examples/cb-ts-to-js/js/app/hero-lifecycle.component.js +++ b/public/docs/_examples/cb-ts-to-js/js/app/hero-lifecycle.component.js @@ -10,10 +10,9 @@ }) ]; // #docregion - HeroComponent.prototype.ngOnInit = - function() { - this.name = 'Windstorm'; - }; + HeroComponent.prototype.ngOnInit = function() { + this.name = 'Windstorm'; + }; // #enddocregion app.HeroesLifecycleModule = diff --git a/public/docs/_examples/cb-ts-to-js/js/app/hero.component.js b/public/docs/_examples/cb-ts-to-js/js/app/hero.component.js index c6a58acc56..745a450096 100644 --- a/public/docs/_examples/cb-ts-to-js/js/app/hero.component.js +++ b/public/docs/_examples/cb-ts-to-js/js/app/hero.component.js @@ -15,13 +15,12 @@ HeroComponent.annotations = [ new ng.core.Component({ selector: 'hero-view', - template: - '

Hero: {{getName()}}

' + template: '

Hero: {{getName()}}

' }) ]; // #docregion constructorproto - HeroComponent.prototype.getName = - function() {return 'Windstorm';}; + + HeroComponent.prototype.getName = function() {return 'Windstorm';}; // #enddocregion constructorproto // #enddocregion metadata diff --git a/public/docs/_examples/cb-ts-to-js/js/app/main.js b/public/docs/_examples/cb-ts-to-js/js/app/main.js index 9091452599..015a8d2126 100644 --- a/public/docs/_examples/cb-ts-to-js/js/app/main.js +++ b/public/docs/_examples/cb-ts-to-js/js/app/main.js @@ -4,12 +4,9 @@ // #enddocregion appimport // #docregion ng2import - var platformBrowserDynamic = - ng.platformBrowserDynamic.platformBrowserDynamic; - var LocationStrategy = - ng.common.LocationStrategy; - var HashLocationStrategy = - ng.common.HashLocationStrategy; + var platformBrowserDynamic = ng.platformBrowserDynamic.platformBrowserDynamic; + var LocationStrategy = ng.common.LocationStrategy; + var HashLocationStrategy = ng.common.HashLocationStrategy; // #enddocregion ng2import // #docregion appimport diff --git a/public/docs/_examples/cb-ts-to-js/ts/app/hero-di-inject-additional.component.ts b/public/docs/_examples/cb-ts-to-js/ts/app/hero-di-inject-additional.component.ts index 146c6cbd83..d36b3eff19 100644 --- a/public/docs/_examples/cb-ts-to-js/ts/app/hero-di-inject-additional.component.ts +++ b/public/docs/_examples/cb-ts-to-js/ts/app/hero-di-inject-additional.component.ts @@ -19,12 +19,9 @@ import { BrowserModule } from '@angular/platform-browser'; class TitleComponent { private msg: string = ''; constructor( - @Inject('titlePrefix') - @Optional() - private titlePrefix: string, - @Attribute('title') - private title: string) { - } + @Inject('titlePrefix') @Optional() private titlePrefix: string, + @Attribute('title') private title: string + ) { } ok() { this.msg = 'OK!'; diff --git a/public/docs/_examples/cb-ts-to-js/ts/app/hero-di-inject.component.ts b/public/docs/_examples/cb-ts-to-js/ts/app/hero-di-inject.component.ts index 7dc2bc84a2..eb2cb78971 100644 --- a/public/docs/_examples/cb-ts-to-js/ts/app/hero-di-inject.component.ts +++ b/public/docs/_examples/cb-ts-to-js/ts/app/hero-di-inject.component.ts @@ -7,10 +7,7 @@ import { BrowserModule } from '@angular/platform-browser'; template: `

Hero: {{name}}

` }) class HeroComponent { - constructor( - @Inject('heroName') - private name: string) { - } + constructor(@Inject('heroName') private name: string) { } } // #enddocregion diff --git a/public/docs/_examples/cb-ts-to-js/ts/app/hero-di.component.ts b/public/docs/_examples/cb-ts-to-js/ts/app/hero-di.component.ts index a20453ef0a..c1bb927219 100644 --- a/public/docs/_examples/cb-ts-to-js/ts/app/hero-di.component.ts +++ b/public/docs/_examples/cb-ts-to-js/ts/app/hero-di.component.ts @@ -8,6 +8,7 @@ import { DataService } from './data.service'; selector: 'hero-di', template: `

Hero: {{name}}

` }) + class HeroComponent { name: string; constructor(dataService: DataService) { diff --git a/public/docs/_examples/cb-ts-to-js/ts/app/hero-lifecycle.component.ts b/public/docs/_examples/cb-ts-to-js/ts/app/hero-lifecycle.component.ts index 1181c71cc9..64bdc9e927 100644 --- a/public/docs/_examples/cb-ts-to-js/ts/app/hero-lifecycle.component.ts +++ b/public/docs/_examples/cb-ts-to-js/ts/app/hero-lifecycle.component.ts @@ -10,8 +10,7 @@ import { BrowserModule } from '@angular/platform-browser'; template: `

Hero: {{name}}

` }) // #docregion -class HeroComponent - implements OnInit { +class HeroComponent implements OnInit { name: string; ngOnInit() { this.name = 'Windstorm'; diff --git a/public/docs/_examples/cb-ts-to-js/ts/app/heroes-bindings.component.ts b/public/docs/_examples/cb-ts-to-js/ts/app/heroes-bindings.component.ts index 407b8b0e29..0ce026a42f 100644 --- a/public/docs/_examples/cb-ts-to-js/ts/app/heroes-bindings.component.ts +++ b/public/docs/_examples/cb-ts-to-js/ts/app/heroes-bindings.component.ts @@ -9,14 +9,15 @@ import { BrowserModule } from '@angular/platform-browser'; // #docregion @Component({ selector: 'heroes-bindings', - template: `

- Tour of Heroes -

` + template: ` +

+ Tour of Heroes +

+ ` }) class HeroesComponent { @HostBinding() title = 'Tooltip content'; - @HostBinding('class.heading') - hClass = true; + @HostBinding('class.heading') hClass = true; active: boolean; constructor() {} diff --git a/public/docs/_examples/package.json b/public/docs/_examples/package.json index a46ac1b718..5aeaa55c1f 100644 --- a/public/docs/_examples/package.json +++ b/public/docs/_examples/package.json @@ -27,7 +27,7 @@ "@angular/router": "~3.1.1", "@angular/upgrade": "~2.1.1", - "angular-in-memory-web-api": "~0.1.13", + "angular-in-memory-web-api": "~0.1.14", "core-js": "^2.4.1", "reflect-metadata": "^0.1.8", "rollup": "^0.36.0", @@ -51,6 +51,9 @@ "@types/selenium-webdriver": "^2.53.32", "angular2-template-loader": "^0.4.0", "awesome-typescript-loader": "^2.2.4", + "babel-cli": "^6.16.0", + "babel-preset-angular2": "^0.0.2", + "babel-preset-es2015": "^6.16.0", "canonical-path": "0.0.2", "concurrently": "^3.0.0", "css-loader": "^0.25.0", diff --git a/public/docs/js/latest/cookbook/ts-to-js.jade b/public/docs/js/latest/cookbook/ts-to-js.jade index a76d90bce7..1ed9ac2489 100644 --- a/public/docs/js/latest/cookbook/ts-to-js.jade +++ b/public/docs/js/latest/cookbook/ts-to-js.jade @@ -16,6 +16,8 @@ include ../../../../_includes/_util-fns :marked ## Table of contents + [From TS to ES6 to ES5](#from-ts) + [Modularity: imports and exports](#modularity) [Classes and Class Metadata](#class-metadata) @@ -24,90 +26,127 @@ include ../../../../_includes/_util-fns [Dependency Injection](#dependency-injection) - [Host and Query Metadata](#other-property-metadata) + [Host and Query Metadata](#host-query-metadata) **Run and compare the live TypeScript and JavaScript code shown in this cookbook.** +a(id="from-ts") +.l-main-section +:marked + ## From TS to ES6 to ES5 + + Since TypeScript is a superset of ES6 JavaScript, and ES6 itself is a superset of ES5, the + transformation of Typescript code all the way to ES5 javascript can be seen as "shedding" + features. + + When going from TypeScript to ES6 with decorators, we mostly remove + [type annotations](https://www.typescriptlang.org/docs/handbook/basic-types.html) + , such as `string` or `boolean`, and + [class property modifiers](http://www.typescriptlang.org/docs/handbook/classes.html#public-private-and-protected-modifiers) + such as `public` and `private`. + The exception is type annotations used for dependency injection, which can be kept. + + Going from ES6 with decorators to plain ES6 JavaScript we lose all + [decorators](https://www.typescriptlang.org/docs/handbook/decorators.html) + and the remaining type annotations. + We also lose class properties, which now have to be declared in the class constructor. + + Finally, in the transition from ES6 to ES5 JavaScript the main missing features are `import` + statements and `class` declarations. + + For ES6 transpilation we recommend using a similar setup as our TypeScript quickstart, + replacing TypeScript with [Babel](https://babeljs.io/) using the `es2015` preset. + To use decorators and annotations with Babel, install the + [`angular2`](https://github.com/shuhei/babel-plugin-angular2-annotations) preset as well. + a(id="modularity") .l-main-section :marked ## Importing and Exporting -- var top="vertical-align:top" -table(width="100%") - col(width="50%") - col(width="50%") - tr - th TypeScript - th ES5 JavaScript - tr(style=top) - td - :marked - ### Importing Angular Code + ### Importing Angular Code - In TypeScript code, Angular classes, functions, and other members - are imported with TypeScript `import` statements: + In TypeScript and ES6 JavaScript, Angular classes, functions, and other members are imported + with ES6 `import` statements. - +makeExample('cb-ts-to-js/ts/app/main.ts', 'ng2import')(format="." ) + In ES5 JavaScript code, when using [the Angular packages](../glossary.html#!#scoped-package), + we can access Angular code through the global `ng` object. In the nested members of this + object we'll find everything we would import from `@angular` in TypeScript: - td - :marked - ### Accessing Angular Code through the ng global ++makeTabs(` + cb-ts-to-js/ts/app/main.ts, + cb-ts-to-js/js-es6-decorators/app/main.es6, + cb-ts-to-js/js-es6/app/main.es6, + cb-ts-to-js/js/app/main.js + `,` + ng2import, + ng2import, + ng2import, + ng2import + `,` + Typescript, + ES6 JavaScript with decorators, + ES6 JavaScript, + ES5 JavaScript + `) - In JavaScript code, when using - [the Angular packages](../glossary.html#!#scoped-package), - we can access Angular code through the global `ng` object. In the - nested members of this object we'll find everything we would import - from `@angular` in TypeScript: +:marked + ### Importing and Exporting Application Code - +makeExample('cb-ts-to-js/js/app/main.js', 'ng2import')(format="." ) + Each file in an Angular TypeScript or ES6 JavaScript application constitutes a ES6 module. + When we want to make something from a module available to other modules, we `export` it. - tr(style=top) - td - :marked - ### Importing and Exporting Application Code + In an Angular ES5 JavaScript application, we load each file to the page using a `