diff --git a/public/docs/_examples/cb-ts-to-js/e2e-spec.js b/public/docs/_examples/cb-ts-to-js/e2e-spec.js new file mode 100644 index 0000000000..27b332e99e --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/e2e-spec.js @@ -0,0 +1,73 @@ +describe('TypeScript to Javascript tests', function () { + + beforeAll(function () { + browser.get(''); + }); + + it('should display the basic component example', function () { + testTag('hero-view', 'Hero: Windstorm'); + }); + + it('should display the component example with lifecycle methods', function () { + testTag('hero-lifecycle', 'Hero: Windstorm'); + }); + + it('should display component with DI example', function () { + testTag('hero-di', 'Hero: Windstorm'); + }); + + it('should display component with DI using @Inject example', function () { + testTag('hero-di-inject', 'Hero: Windstorm'); + }); + + it('should support optional, attribute, and query injections', function () { + var app = element(by.css('hero-di-inject-additional')); + var h1 = app.element(by.css('h1')); + var okMsg = app.element(by.css('.ok-msg')); + + expect(h1.getText()).toBe('Tour of Heroes'); + app.element(by.buttonText('OK')).click(); + expect(okMsg.getText()).toBe('OK!'); + }); + + it('should support component with inputs and outputs', function () { + var app = element(by.css('hero-io')); + var confirmComponent = app.element(by.css('my-confirm')); + + confirmComponent.element(by.buttonText('OK')).click(); + expect(app.element(by.cssContainingText('span', 'OK clicked')).isPresent()).toBe(true); + + confirmComponent.element(by.buttonText('Cancel')).click(); + expect(app.element(by.cssContainingText('span', 'Cancel clicked')).isPresent()).toBe(true); + }); + + it('should support host bindings and host listeners', function() { + var app = element(by.css('heroes-bindings')); + var h1 = app.element(by.css('h1')); + + expect(app.getAttribute('class')).toBe('heading'); + expect(app.getAttribute('title')).toBe('Tooltip content'); + + h1.click(); + expect(h1.getAttribute('class')).toBe('active'); + + h1.click(); + browser.actions().doubleClick(h1).perform(); + expect(h1.getAttribute('class')).toBe('active'); + }); + + it('should support content and view queries', function() { + var app = element(by.css('heroes-queries')); + var windstorm = app.element(by.css('hero:first-child')); + + app.element(by.buttonText('Activate')).click(); + expect(windstorm.element(by.css('h2')).getAttribute('class')).toBe('active'); + expect(windstorm.element(by.css('active-label')).getText()).toBe('Active'); + }); + + function testTag(selector, expectedText) { + var component = element(by.css(selector)); + expect(component.getText()).toBe(expectedText); + } + +}); diff --git a/public/docs/_examples/cb-ts-to-js/js/app/data.service.js b/public/docs/_examples/cb-ts-to-js/js/app/data.service.js new file mode 100644 index 0000000000..c060e2b39d --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js/app/data.service.js @@ -0,0 +1,13 @@ +(function(app) { + + function DataService() { + } + DataService.annotations = [ + new ng.core.Injectable() + ]; + DataService.prototype.getHeroName = function() { + return 'Windstorm'; + }; + app.DataService = DataService; + +})(window.app = window.app || {}); 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 new file mode 100644 index 0000000000..413ccfc8f3 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js/app/hero-di-inject-additional.component.js @@ -0,0 +1,47 @@ +(function(app) { + + // #docregion + var TitleComponent = ng.core.Component({ + selector: 'hero-title', + template: + '

{{titlePrefix}} {{title}}

' + + '' + + '' + }).Class({ + constructor: [ + [ + new ng.core.Optional(), + new ng.core.Inject('titlePrefix') + ], + new ng.core.Attribute('title'), + [ + new ng.core.Query('okMsg'), + ng.core.ElementRef + ], + function(titlePrefix, title, msg) { + this.titlePrefix = titlePrefix; + this.title = title; + this.msg = msg; + } + ], + ok: function() { + var msgEl = + this.msg.first.nativeElement; + msgEl.textContent = 'OK!'; + } + }); + // #enddocregion + + var AppComponent = ng.core.Component({ + selector: 'hero-di-inject-additional', + template: '' + + '' + + '', + directives: [TitleComponent] + }).Class({ + constructor: function() { } + }); + + app.HeroDIInjectAdditionalComponent = AppComponent; + +})(window.app = window.app || {}); 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 new file mode 100644 index 0000000000..71bdbb57f9 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js/app/hero-di-inject.component.js @@ -0,0 +1,39 @@ +(function(app) { + +// #docregion parameters + function HeroComponent(name) { + this.name = name; + } + HeroComponent.parameters = [ + 'heroName' + ]; + HeroComponent.annotations = [ + new ng.core.Component({ + selector: 'hero-di-inject', + template: '

Hero: {{name}}

' + }) + ]; +// #enddocregion parameters + + app.HeroDIInjectComponent = HeroComponent; + +})(window.app = window.app || {}); + +(function(app) { +// #docregion ctor + var HeroComponent = ng.core.Component({ + selector: 'hero-di-inline2', + template: '

Hero: {{name}}

' + }) + .Class({ + constructor: + [new ng.core.Inject('heroName'), + function(name) { + this.name = name; + }] + }); +// #enddocregion ctor + + app.HeroDIInjectComponent2 = HeroComponent; + +})(window.app = window.app || {}); 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 new file mode 100644 index 0000000000..90c3d69cba --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js/app/hero-di-inline.component.js @@ -0,0 +1,16 @@ +(function(app) { + // #docregion + var HeroComponent = ng.core.Component({ + selector: 'hero-di-inline', + template: '

Hero: {{name}}

' + }) + .Class({ + constructor: + [app.DataService, + function(service) { + this.name = service.getHeroName(); + }] + }); + // #enddocregion + app.HeroDIInlineComponent = HeroComponent; +})(window.app = window.app || {}); 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 new file mode 100644 index 0000000000..2963258292 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js/app/hero-di.component.js @@ -0,0 +1,20 @@ +(function(app) { + + // #docregion + app.HeroDIComponent = HeroComponent; + + function HeroComponent(dataService) { + this.name = dataService.getHeroName(); + } + HeroComponent.parameters = [ + app.DataService + ]; + HeroComponent.annotations = [ + new ng.core.Component({ + selector: 'hero-di', + template: '

Hero: {{name}}

' + }) + ]; + // #enddocregion + +})(window.app = window.app || {}); 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 new file mode 100644 index 0000000000..2890e006a2 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js/app/hero-dsl.component.js @@ -0,0 +1,23 @@ +// #docplaster +// #docregion appexport +(function(app) { + + // #docregion component + var HeroComponent = ng.core.Component({ + selector: 'hero-view-2', + template: + '

Name: {{getName()}}

', + }) + .Class({ + constructor: function() { + }, + getName: function() { + return 'Windstorm'; + } + }); + // #enddocregion component + + app.HeroComponentDsl = HeroComponent; + +})(window.app = window.app || {}); +// #enddocregion appexport diff --git a/public/docs/_examples/cb-ts-to-js/js/app/hero-io.component.js b/public/docs/_examples/cb-ts-to-js/js/app/hero-io.component.js new file mode 100644 index 0000000000..f00ce8065c --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js/app/hero-io.component.js @@ -0,0 +1,57 @@ +(function(app) { + // #docregion + var ConfirmComponent = ng.core.Component({ + selector: 'my-confirm', + inputs: [ + 'okMsg', + 'notOkMsg: cancelMsg' + ], + outputs: [ + 'ok', + 'notOk: cancel' + ], + template: + '' + + '' + }).Class({ + constructor: function() { + this.ok = new ng.core.EventEmitter(); + this.notOk = new ng.core.EventEmitter(); + }, + onOkClick: function() { + this.ok.next(true); + }, + onNotOkClick: function() { + this.notOk.next(true); + } + }); + // #enddocregion + + function AppComponent() { + } + AppComponent.annotations = [ + new ng.core.Component({ + selector: 'hero-io', + template: '' + + '' + + 'OK clicked' + + 'Cancel clicked', + directives: [ConfirmComponent] + }) + ]; + AppComponent.prototype.onOk = function() { + this.okClicked = true; + } + AppComponent.prototype.onCancel = function() { + this.cancelClicked = true; + } + app.HeroIOComponent = AppComponent; + +})(window.app = window.app || {}); 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 new file mode 100644 index 0000000000..b8a2148a64 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js/app/hero-lifecycle.component.js @@ -0,0 +1,21 @@ +// #docplaster +(function(app) { + // #docregion + function HeroComponent() {} + // #enddocregion + HeroComponent.annotations = [ + new ng.core.Component({ + selector: 'hero-lifecycle', + template: '

Hero: {{name}}

' + }) + ]; + // #docregion + HeroComponent.prototype.ngOnInit = + function() { + this.name = 'Windstorm'; + }; + // #enddocregion + + app.HeroLifecycleComponent = HeroComponent; + +})(window.app = window.app || {}); 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 new file mode 100644 index 0000000000..f741285617 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js/app/hero.component.js @@ -0,0 +1,32 @@ +// #docplaster +// #docregion appexport +(function(app) { + // #enddocregion appexport + + // #docregion metadata + // #docregion appexport + // #docregion constructorproto + function HeroComponent() { + this.title = "Hero Detail"; + } + + // #enddocregion constructorproto + // #enddocregion appexport + HeroComponent.annotations = [ + new ng.core.Component({ + selector: 'hero-view', + template: + '

Hero: {{getName()}}

' + }) + ]; + // #docregion constructorproto + HeroComponent.prototype.getName = + function() {return 'Windstorm';}; + // #enddocregion constructorproto + // #enddocregion metadata + + // #docregion appexport + app.HeroComponent = HeroComponent; + +})(window.app = window.app || {}); +// #enddocregion appexport diff --git a/public/docs/_examples/cb-ts-to-js/js/app/heroes-bindings.component.js b/public/docs/_examples/cb-ts-to-js/js/app/heroes-bindings.component.js new file mode 100644 index 0000000000..0c4ee7d7cf --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js/app/heroes-bindings.component.js @@ -0,0 +1,30 @@ +(function(app) { + + // #docregion + var HeroesComponent = ng.core.Component({ + selector: 'heroes-bindings', + template: '

' + + 'Tour of Heroes' + + '

', + host: { + '[title]': 'title', + '[class.heading]': 'hClass', + '(click)': 'clicked()', + '(dblclick)': 'doubleClicked($event)' + } + }).Class({ + constructor: function() { + this.title = 'Tooltip content'; + this.hClass = true; + }, + clicked: function() { + this.active = !this.active; + }, + doubleClicked: function(evt) { + this.active = true; + } + }); + // #enddocregion + app.HeroesHostBindingsComponent = HeroesComponent; + +})(window.app = window.app || {}); diff --git a/public/docs/_examples/cb-ts-to-js/js/app/heroes-queries.component.js b/public/docs/_examples/cb-ts-to-js/js/app/heroes-queries.component.js new file mode 100644 index 0000000000..a99d985b35 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js/app/heroes-queries.component.js @@ -0,0 +1,73 @@ +(function(app) { + + var ActiveLabelComponent = ng.core.Component({ + selector: 'active-label', + template: '' + + 'Active' + + '' + }).Class({ + constructor: function() { }, + activate: function() { + this.active = true; + } + }); + + // #docregion content + var HeroComponent = ng.core.Component({ + selector: 'hero', + template: '

' + + '{{hero.name}} ' + + '' + + '

', + inputs: ['hero'], + queries: { + label: new ng.core.ContentChild( + ActiveLabelComponent) + } + }).Class({ + constructor: function() { }, + activate: function() { + this.active = true; + this.label.activate(); + } + }); + // #enddocregion content + + // #docregion view + var AppComponent = ng.core.Component({ + selector: 'heroes-queries', + template: + '' + + '' + + '' + + '', + directives: [ + HeroComponent, + ActiveLabelComponent + ], + queries: { + heroCmps: new ng.core.ViewChildren( + HeroComponent) + } + }).Class({ + constructor: function() { + this.heroData = [ + {id: 1, name: 'Windstorm'}, + {id: 2, name: 'Superman'} + ]; + }, + activate: function() { + this.heroCmps.forEach(function(cmp) { + cmp.activate(); + }); + } + }); + // #enddocregion view + + app.HeroesQueriesComponent = AppComponent; + +})(window.app = window.app || {}); 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 new file mode 100644 index 0000000000..8603b116cc --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js/app/main.js @@ -0,0 +1,41 @@ +// #docplaster +// #docregion appimport +(function(app) { + // #enddocregion appimport + + // #docregion ng2import + var provide = + ng.core.provide; + var bootstrap = + ng.platform.browser.bootstrap; + var LocationStrategy = + ng.router.LocationStrategy; + var HashLocationStrategy = + ng.router.HashLocationStrategy; + // #enddocregion ng2import + + // #docregion appimport + var HeroComponent = app.HeroComponent; + // #enddocregion appimport + + document.addEventListener('DOMContentLoaded', function() { + bootstrap(HeroComponent); + bootstrap(app.HeroComponentDsl); + bootstrap(app.HeroLifecycleComponent); + bootstrap(app.HeroDIComponent, [app.DataService]); + bootstrap(app.HeroDIInlineComponent, [app.DataService]); + bootstrap(app.HeroDIInjectComponent, [ + ng.core.provide('heroName', {useValue: 'Windstorm'}) + ]); + bootstrap(app.HeroDIInjectComponent2, [ + ng.core.provide('heroName', {useValue: 'Bombasto'}) + ]); + bootstrap(app.HeroDIInjectAdditionalComponent); + bootstrap(app.HeroIOComponent); + bootstrap(app.HeroesHostBindingsComponent); + bootstrap(app.HeroesQueriesComponent); + }); + + // #docregion appimport +})(window.app = window.app || {}); +// #enddocregion appimport diff --git a/public/docs/_examples/cb-ts-to-js/js/example-config.json b/public/docs/_examples/cb-ts-to-js/js/example-config.json new file mode 100644 index 0000000000..e69de29bb2 diff --git a/public/docs/_examples/cb-ts-to-js/js/index.html b/public/docs/_examples/cb-ts-to-js/js/index.html new file mode 100644 index 0000000000..549d5247ee --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js/index.html @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

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-view2... + Loading hero-lifecycle... + +
+

Input and Output Metadata

+ Loading hero-io... + +
+

Dependency Injection

+ Loading hero-di... + Loading hero-di-inline... + Loading hero-di-inline2... + 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/plnkr.json b/public/docs/_examples/cb-ts-to-js/js/plnkr.json new file mode 100644 index 0000000000..729230c2d1 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/js/plnkr.json @@ -0,0 +1,7 @@ +{ + "description": "TypeScript to JavaScript", + "files":[ + "!**/karma*.*" + ], + "tags":["cookbook"] +} diff --git a/public/docs/_examples/cb-ts-to-js/ts/.gitignore b/public/docs/_examples/cb-ts-to-js/ts/.gitignore new file mode 100644 index 0000000000..2cb7d2a2e9 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/ts/.gitignore @@ -0,0 +1 @@ +**/*.js diff --git a/public/docs/_examples/cb-ts-to-js/ts/app/data.service.ts b/public/docs/_examples/cb-ts-to-js/ts/app/data.service.ts new file mode 100644 index 0000000000..08911a96a2 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/ts/app/data.service.ts @@ -0,0 +1,10 @@ +import {Injectable} from 'angular2/core'; + +@Injectable() +export class DataService { + constructor() { + } + getHeroName() { + return 'Windstorm'; + } +} 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 new file mode 100644 index 0000000000..9f3e37a7d8 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/ts/app/hero-di-inject-additional.component.ts @@ -0,0 +1,48 @@ +import { + Attribute, + Component, + ElementRef, + Inject, + Optional, + Query, + QueryList +} from 'angular2/core'; + +// #docregion +@Component({ + selector: 'hero-title', + template: ` +

{{titlePrefix}} {{title}}

+ + + ` +}) +export class TitleComponent { + constructor( + @Inject('titlePrefix') + @Optional() + private titlePrefix:string, + @Attribute('title') + private title:string, + @Query('okMsg') + private msg:QueryList) { + } + + ok() { + let msgEl = + this.msg.first.nativeElement; + msgEl.textContent = 'OK!'; + } +} +// #enddocregion + +@Component({ + selector: 'hero-di-inject-additional', + template: ` + + `, + directives: [TitleComponent] +}) +export class AppComponent { + +} 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 new file mode 100644 index 0000000000..1633598426 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/ts/app/hero-di-inject.component.ts @@ -0,0 +1,14 @@ +import {Component, Inject} from 'angular2/core'; + +// #docregion +@Component({ + selector: 'hero-di-inject', + template: `

Hero: {{name}}

` +}) +export class HeroComponent { + 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 new file mode 100644 index 0000000000..58f12db09c --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/ts/app/hero-di.component.ts @@ -0,0 +1,15 @@ +import {Component} from 'angular2/core'; +import {DataService} from './data.service'; + +// #docregion +@Component({ + selector: 'hero-di', + template: `

Hero: {{name}}

` +}) +export class HeroComponent { + name:string; + constructor(dataService:DataService) { + this.name = dataService.getHeroName(); + } +} +// #enddocregion diff --git a/public/docs/_examples/cb-ts-to-js/ts/app/hero-io.component.ts b/public/docs/_examples/cb-ts-to-js/ts/app/hero-io.component.ts new file mode 100644 index 0000000000..01ce84d8b3 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/ts/app/hero-io.component.ts @@ -0,0 +1,56 @@ +import {Component, EventEmitter, Input, Output} from 'angular2/core'; + +// #docregion +@Component({ + selector: 'my-confirm', + template: ` + + + ` +}) +export class ConfirmComponent { + @Input() okMsg:string; + @Input('cancelMsg') notOkMsg:string; + @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 + `, + directives: [ConfirmComponent] +}) +export class AppComponent { + okClicked:boolean; + cancelClicked:boolean; + + onOk() { + this.okClicked = true; + } + onCancel() { + this.cancelClicked = true; + } +} 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 new file mode 100644 index 0000000000..2a82e9cd20 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/ts/app/hero-lifecycle.component.ts @@ -0,0 +1,19 @@ +// #docplaster +// #docregion +import {Component, OnInit} + from 'angular2/core'; + // #enddocregion + +@Component({ + selector: 'hero-lifecycle', + template: `

Hero: {{name}}

` +}) +// #docregion +export class HeroComponent + implements OnInit { + name:string; + ngOnInit() { + this.name = 'Windstorm'; + } +} +// #enddocregion diff --git a/public/docs/_examples/cb-ts-to-js/ts/app/hero.component.ts b/public/docs/_examples/cb-ts-to-js/ts/app/hero.component.ts new file mode 100644 index 0000000000..1ce2609636 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/ts/app/hero.component.ts @@ -0,0 +1,18 @@ +// #docplaster +// #docregion metadata +import {Component} from 'angular2/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 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 new file mode 100644 index 0000000000..6512f41d68 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/ts/app/heroes-bindings.component.ts @@ -0,0 +1,28 @@ +import {Component, HostBinding, HostListener} from 'angular2/core'; + +// #docregion +@Component({ + selector: 'heroes-bindings', + template: `

+ Tour of Heroes +

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

+ {{hero.name}} + +

` +}) +class HeroComponent { + @Input() hero:any; + active:boolean; + + @ContentChild(ActiveLabelComponent) + label:ActiveLabelComponent + + activate() { + this.active = true; + this.label.activate(); + } +} +// #enddocregion content + + +// #docregion view +@Component({ + selector: 'heroes-queries', + template: ` + + + + + `, + directives: [ + HeroComponent, + ActiveLabelComponent + ] +}) +export class HeroesQueriesComponent { + heroData = [ + {id: 1, name: 'Windstorm'}, + {id: 2, name: 'Superman'} + ]; + + @ViewChildren(HeroComponent) + heroCmps:QueryList; + + activate() { + this.heroCmps.forEach( + (cmp) => cmp.activate() + ); + } +} +// #enddocregion view diff --git a/public/docs/_examples/cb-ts-to-js/ts/app/main.ts b/public/docs/_examples/cb-ts-to-js/ts/app/main.ts new file mode 100644 index 0000000000..02535f55f8 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/ts/app/main.ts @@ -0,0 +1,35 @@ +// #docregion ng2import +import {provide} + from 'angular2/core'; +import {bootstrap} + from 'angular2/platform/browser'; +import { + LocationStrategy, + HashLocationStrategy +} from 'angular2/router'; +// #enddocregion ng2import + +// #docregion appimport +import {HeroComponent} + from './hero.component'; +// #enddocregion appimport +import {HeroComponent as HeroLifecycleComponent} from './hero-lifecycle.component'; +import {HeroComponent as HeroDIComponent} from './hero-di.component'; +import {HeroComponent as HeroDIInjectComponent} from './hero-di-inject.component'; +import {AppComponent as AppDIInjectAdditionalComponent} from './hero-di-inject-additional.component'; +import {AppComponent as AppIOComponent} from './hero-io.component'; +import {HeroesComponent as HeroesHostBindingsComponent} from './heroes-bindings.component'; +import {HeroesQueriesComponent} from './heroes-queries.component'; + +import {DataService} from './data.service'; + +bootstrap(HeroComponent); +bootstrap(HeroLifecycleComponent); +bootstrap(HeroDIComponent, [DataService]); +bootstrap(HeroDIInjectComponent, [ + provide('heroName', {useValue: 'Windstorm'}) +]); +bootstrap(AppDIInjectAdditionalComponent); +bootstrap(AppIOComponent); +bootstrap(HeroesHostBindingsComponent); +bootstrap(HeroesQueriesComponent); diff --git a/public/docs/_examples/cb-ts-to-js/ts/example-config.json b/public/docs/_examples/cb-ts-to-js/ts/example-config.json new file mode 100644 index 0000000000..e69de29bb2 diff --git a/public/docs/_examples/cb-ts-to-js/ts/index.html b/public/docs/_examples/cb-ts-to-js/ts/index.html new file mode 100644 index 0000000000..49a1cf88e8 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/ts/index.html @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + +

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/ts/plnkr.json b/public/docs/_examples/cb-ts-to-js/ts/plnkr.json new file mode 100644 index 0000000000..5c7a5acd44 --- /dev/null +++ b/public/docs/_examples/cb-ts-to-js/ts/plnkr.json @@ -0,0 +1,8 @@ +{ + "description": "TypeScript to JavaScript", + "files":[ + "!**/*.d.ts", + "!**/*.js" + ], + "tags":["cookbook"] +} diff --git a/public/docs/dart/latest/cookbook/_data.json b/public/docs/dart/latest/cookbook/_data.json index 71d17069b1..4d4757ee57 100644 --- a/public/docs/dart/latest/cookbook/_data.json +++ b/public/docs/dart/latest/cookbook/_data.json @@ -2,18 +2,30 @@ "index": { "title": "Cookbook", "navTitle": "Overview", - "description": "A collection of recipes for common Angular application scenarios" + "intro": "A collection of recipes for common Angular application scenarios" }, "a1-a2-quick-reference": { "title": "Angular 1 to 2 Quick Reference", "navTitle": "Angular 1 to 2 Quick Ref", - "description": "Learn how Angular 1 concepts and techniques map to Angular 2", + "intro": "Learn how Angular 1 concepts and techniques map to Angular 2", "hide": true }, "component-communication": { "title": "Component Interaction", - "description": "Share information between different directives and components" + "intro": "Share information between different directives and components" + }, + + "dynamic-form": { + "title": "Dynamic Form", + "intro": "Render dynamic forms with NgFormModel", + "hide": true + }, + + "ts-to-js": { + "title": "TypeScript to JavaScript", + "intro": "Convert Angular 2 TypeScript examples into ES5 JavaScript", + "hide": true } } \ No newline at end of file diff --git a/public/docs/dart/latest/cookbook/dynamic-forms.jade b/public/docs/dart/latest/cookbook/dynamic-forms.jade new file mode 100644 index 0000000000..f8df2a84a6 --- /dev/null +++ b/public/docs/dart/latest/cookbook/dynamic-forms.jade @@ -0,0 +1 @@ +!= partial("../../../_includes/_ts-temp") \ No newline at end of file diff --git a/public/docs/dart/latest/cookbook/ts-to-js.jade b/public/docs/dart/latest/cookbook/ts-to-js.jade new file mode 100644 index 0000000000..f8df2a84a6 --- /dev/null +++ b/public/docs/dart/latest/cookbook/ts-to-js.jade @@ -0,0 +1 @@ +!= partial("../../../_includes/_ts-temp") \ No newline at end of file diff --git a/public/docs/js/latest/_data.json b/public/docs/js/latest/_data.json index 8c221c6385..a29440ca88 100644 --- a/public/docs/js/latest/_data.json +++ b/public/docs/js/latest/_data.json @@ -35,7 +35,7 @@ "title": "API Preview", "reference": true }, - + "cheatsheet": { "title": "Angular Cheat Sheet", "intro": "A quick quide to Angular syntax.", @@ -47,7 +47,7 @@ "intro": "Brief definitions of the most important words in the Angular 2 vocabulary", "reference": true }, - + "resources": { "icon": "play-circle-fill", "title": "Angular Resources", @@ -60,7 +60,7 @@ "title": "Help & Support", "resources": true }, - + "styleguide": { "title": "Docs Style Guide", "intro": "Design & Layout Patterns For Documentation" diff --git a/public/docs/js/latest/cookbook/_data.json b/public/docs/js/latest/cookbook/_data.json index f4bc414f46..dc91a7b4a2 100644 --- a/public/docs/js/latest/cookbook/_data.json +++ b/public/docs/js/latest/cookbook/_data.json @@ -2,17 +2,29 @@ "index": { "title": "Cookbook", "navTitle": "Overview", - "description": "A collection of recipes for common Angular application scenarios" + "intro": "A collection of recipes for common Angular application scenarios" }, - + "a1-a2-quick-reference": { "title": "Angular 1 to 2 Quick Reference", "navTitle": "Angular 1 to 2 Quick Ref", - "description": "Learn how Angular 1 concepts and techniques map to Angular 2" + "intro": "Learn how Angular 1 concepts and techniques map to Angular 2" }, - + "component-communication": { "title": "Component Interaction", - "description": "Share information between different directives and components" + "intro": "Share information between different directives and components" + }, + + "dynamic-form": { + "title": "Dynamic Form", + "intro": "Render dynamic forms with NgFormModel", + "hide": true + }, + + "ts-to-js": { + "title": "TypeScript to JavaScript", + "intro": "Convert Angular 2 TypeScript examples into ES5 JavaScript" } -} \ No newline at end of file + +} diff --git a/public/docs/js/latest/cookbook/dynamic-forms.jade b/public/docs/js/latest/cookbook/dynamic-forms.jade new file mode 100644 index 0000000000..f8df2a84a6 --- /dev/null +++ b/public/docs/js/latest/cookbook/dynamic-forms.jade @@ -0,0 +1 @@ +!= partial("../../../_includes/_ts-temp") \ No newline at end of file diff --git a/public/docs/js/latest/cookbook/index.jade b/public/docs/js/latest/cookbook/index.jade index 6778b6af28..a3a1b000b7 100644 --- a/public/docs/js/latest/cookbook/index.jade +++ b/public/docs/js/latest/cookbook/index.jade @@ -1 +1,3 @@ -!= partial("../../../_includes/_ts-temp") +include ../../../../_includes/_util-fns + ++includeShared('../../../ts/latest/cookbook/index.jade', 'cookbook') diff --git a/public/docs/js/latest/cookbook/ts-to-js.jade b/public/docs/js/latest/cookbook/ts-to-js.jade new file mode 100644 index 0000000000..b6cd2843ef --- /dev/null +++ b/public/docs/js/latest/cookbook/ts-to-js.jade @@ -0,0 +1,471 @@ +include ../../../../_includes/_util-fns + +:marked + Everything that we can do in Angular 2 in TypeScript, we can also do + in JavaScript. Translating from one language to the other is mostly a + matter of changing the way we organize our code and the way we access + Angular 2 APIs. + + Since TypeScript is a popular language option in Angular 2, many of the + code examples you see on the Internet as well as on this site are written + in TypeScript. This cookbook contains recipes for translating these kinds of + code examples to ES5, so that they can be applied to Angular 2 JavaScript + applications. + + +:marked + ## Table of contents + + [Modularity: imports and exports](#modularity) + + [Classes and Class Metadata](#class-metadata) + + [Input and Output Metadata](#property-metadata) + + [Dependency Injection](#dependency-injection) + + [Host and Query Metadata](#other-property-metadata) + + **Run and compare the live [TypeScript](/resources/live-examples/cb-ts-to-js/ts/plnkr.html) and + [JavaScript](/resources/live-examples/cb-ts-to-js/js/plnkr.html) code shown in this cookbook.** + +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 2 Code + + In TypeScript code, Angular 2 classes, functions, and other members + are imported with TypeScript `import` statements: + + +makeExample('cb-ts-to-js/ts/app/main.ts', 'ng2import')(format="." ) + + td + :marked + ### Accessing Angular 2 Code through the ng global + + In JavaScript code, when using + [the Angular 2 UMD bundles](https://github.com/angular/angular/blob/master/modules/angular2/docs/bundles/overview.md), + 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 `angular2` in TypeScript: + + +makeExample('cb-ts-to-js/js/app/main.js', 'ng2import')(format="." ) + + tr(style=top) + td + :marked + ### Importing and Exporting Application Code + + Each file in an Angular 2 TypeScript application constitutes a + TypeScript module. When we want to make something from a module available + to other modules, we `export` it. + + +makeExample('cb-ts-to-js/ts/app/hero.component.ts', 'appexport')(format="." ) + + :marked + In other modules we can then `import` things that have been exported + elsewhere. + + +makeExample('cb-ts-to-js/ts/app/main.ts', 'appimport')(format="." ) + + td + :marked + ### Sharing Application Code + + In an Angular 2 JavaScript application, we load each file to the page + using a `