diff --git a/public/docs/_examples/toh-1/dart-snippets/app_component_snippets_pt1.dart b/public/docs/_examples/toh-1/dart-snippets/app_component_snippets_pt1.dart new file mode 100644 index 0000000000..1a33bbd069 --- /dev/null +++ b/public/docs/_examples/toh-1/dart-snippets/app_component_snippets_pt1.dart @@ -0,0 +1,43 @@ +// #docregion show-hero +template: '

{{title}}

{{hero}} details!

' +// #enddocregion show-hero + +// #docregion show-hero-2 +template: '

{{title}}

{{hero.name}} details!

' +// #enddocregion show-hero-2 + +// #docregion show-hero-properties +template: '

{{title}}

{{hero.name}} details!

{{hero.id}}
{{hero.name}}
' +// #enddocregion show-hero-properties + +// #docregion multi-line-strings +template: ''' +

{{title}}

+

{{hero.name}} details!

+
{{hero.id}}
+
{{hero.name}}
+ ''' +// #enddocregion multi-line-strings + +// #docregion editing-Hero +template:''' +

{{title}}

+

{{hero.name}} details!

+
{{hero.id}}
+
+ +
+
+ ''' +// #enddocregion editing-Hero + +// #docregion app-component-1 +class AppComponent { + String title = 'Tour of Heroes'; + Hero hero = 'Windstorm'; +} +// #enddocregion app-component-1 + +// #docregion hero-property-1 +Hero hero = new Hero(1, 'Windstorm'); +// #enddocregion hero-property-1 diff --git a/public/docs/_examples/toh-1/dart/lib/app_component.dart b/public/docs/_examples/toh-1/dart/lib/app_component.dart new file mode 100644 index 0000000000..a7a1e95f4b --- /dev/null +++ b/public/docs/_examples/toh-1/dart/lib/app_component.dart @@ -0,0 +1,29 @@ +// #docregion pt1 +import 'package:angular2/core.dart'; + +// #docregion hero-class-1 +class Hero { + final int id; + String name; + + Hero(this.id, this.name); +} +// #enddocregion hero-class-1 + +@Component( + selector: 'my-app', + template: ''' +

{{title}}

+

{{hero.name}} details!

+
{{hero.id}}
+
+ +
+
+ ''') +class AppComponent { + String title = 'Tour of Heroes'; + Hero hero = new Hero(1, 'Windstorm'); +} + +// #enddocregion pt1 diff --git a/public/docs/_examples/toh-1/dart/pubspec.yaml b/public/docs/_examples/toh-1/dart/pubspec.yaml new file mode 100644 index 0000000000..ddfafde27c --- /dev/null +++ b/public/docs/_examples/toh-1/dart/pubspec.yaml @@ -0,0 +1,15 @@ +name: angular2_tour_of_heroes +version: 0.0.1 +environment: + sdk: '>=1.13.0 <2.0.0' +dependencies: + angular2: 2.0.0-beta.1 + browser: ^0.10.0 + dart_to_js_script_rewriter: ^0.1.0+4 +transformers: +- angular2: + platform_directives: + - package:angular2/common.dart#COMMON_DIRECTIVES + platform_pipes: + - package:angular2/common.dart#COMMON_PIPES + entry_points: web/main.dart diff --git a/public/docs/_examples/toh-1/dart/web/index.html b/public/docs/_examples/toh-1/dart/web/index.html new file mode 100644 index 0000000000..059daeed4c --- /dev/null +++ b/public/docs/_examples/toh-1/dart/web/index.html @@ -0,0 +1,10 @@ + + + + + + + + Loading... + + diff --git a/public/docs/_examples/toh-1/dart/web/main.dart b/public/docs/_examples/toh-1/dart/web/main.dart new file mode 100644 index 0000000000..d5b50195c1 --- /dev/null +++ b/public/docs/_examples/toh-1/dart/web/main.dart @@ -0,0 +1,9 @@ +// #docregion pt1 +import 'package:angular2/bootstrap.dart'; + +import 'package:angular2_tour_of_heroes/app_component.dart'; + +main() { + bootstrap(AppComponent); +} +// #enddocregion pt1 \ No newline at end of file diff --git a/public/docs/_examples/toh-2/dart-snippets/app_component_snippets_pt2.dart b/public/docs/_examples/toh-2/dart-snippets/app_component_snippets_pt2.dart new file mode 100644 index 0000000000..2e3e2438fd --- /dev/null +++ b/public/docs/_examples/toh-2/dart-snippets/app_component_snippets_pt2.dart @@ -0,0 +1,69 @@ +// #docregion ng-for +
  • + {{hero.id}} {{hero.name}} +
  • +// #enddocregion ng-for + +// #docregion heroes-styled +

    My Heroes

    + +// #enddocregion heroes-styled + +// #docregion selectedHero-click +
  • + {{hero.id}} {{hero.name}} +
  • +// #enddocregion selectedHero-click + +// #docregion selectedHero-details +

    {{selectedHero.name}} details!

    +
    {{selectedHero.id}}
    +
    + + +
    +// #enddocregion selectedHero-details + +// #docregion ng-if +
    +

    {{selectedHero.name}} details!

    +
    {{selectedHero.id}}
    +
    + + +
    +
    +// #enddocregion ng-if + +// #docregion hero-array-1 +final List heroes = mockHeroes; +// #enddocregion hero-array-1 + +// #docregion heroes-template-1 +

    My Heroes

    + +// #enddocregion heroes-template-1 + +// #docregion heroes-ngfor-1 +
  • +// #enddocregion heroes-ngfor-1 + +// #docregion class-selected-1 +[class.selected]="hero == selectedHero" +// #enddocregion class-selected-1 + +// #docregion class-selected-2 +
  • + {{hero.id}} {{hero.name}} +
  • +// #enddocregion class-selected-2 diff --git a/public/docs/_examples/toh-2/dart/lib/app_component.dart b/public/docs/_examples/toh-2/dart/lib/app_component.dart new file mode 100644 index 0000000000..29b90af7f7 --- /dev/null +++ b/public/docs/_examples/toh-2/dart/lib/app_component.dart @@ -0,0 +1,114 @@ +// #docregion pt2 +import 'package:angular2/core.dart'; + +class Hero { + final int id; + String name; + + Hero(this.id, this.name); +} + +@Component( + selector: 'my-app', + template: ''' +

    {{title}}

    +

    My Heroes

    + +
    +

    {{selectedHero.name}} details!

    +
    {{selectedHero.id}}
    +
    + + +
    +
    + ''', +// #docregion styles-1 + styles: const [ + ''' + .selected { + background-color: #CFD8DC !important; + color: white; + } + .heroes { + margin: 0 0 2em 0; + list-style-type: none; + padding: 0; + width: 10em; + } + .heroes li { + cursor: pointer; + position: relative; + left: 0; + background-color: #EEE; + margin: .5em; + padding: .3em 0em; + height: 1.6em; + border-radius: 4px; + } + .heroes li.selected:hover { + color: white; + } + .heroes li:hover { + color: #607D8B; + background-color: #EEE; + left: .1em; + } + .heroes .text { + position: relative; + top: -3px; + } + .heroes .badge { + display: inline-block; + font-size: small; + color: white; + padding: 0.8em 0.7em 0em 0.7em; + background-color: #607D8B; + line-height: 1em; + position: relative; + left: -1px; + top: -4px; + height: 1.8em; + margin-right: .8em; + border-radius: 4px 0px 0px 4px; + } + ''' + ]) +// #enddocregion styles-1 +class AppComponent { + final String title = 'Tour of Heroes'; + final List heroes = mockHeroes; +// #docregion selected-hero-1 + Hero selectedHero; +// #enddocregion selected-hero-1 + +// #docregion on-select-1 + onSelect(Hero hero) { + selectedHero = hero; + } +// #enddocregion on-select-1 +} +// #enddocregion pt2 + +// #docregion hero-array +final List mockHeroes = [ + new Hero(11, "Mr. Nice"), + new Hero(12, "Narco"), + new Hero(13, "Bombasto"), + new Hero(14, "Celeritas"), + new Hero(15, "Magneta"), + new Hero(16, "RubberMan"), + new Hero(17, "Dynama"), + new Hero(18, "Dr IQ"), + new Hero(19, "Magma"), + new Hero(20, "Tornado") +]; +// #enddocregion hero-array + +// #enddocregion pt2 diff --git a/public/docs/_examples/toh-2/dart/pubspec.yaml b/public/docs/_examples/toh-2/dart/pubspec.yaml new file mode 100644 index 0000000000..ddfafde27c --- /dev/null +++ b/public/docs/_examples/toh-2/dart/pubspec.yaml @@ -0,0 +1,15 @@ +name: angular2_tour_of_heroes +version: 0.0.1 +environment: + sdk: '>=1.13.0 <2.0.0' +dependencies: + angular2: 2.0.0-beta.1 + browser: ^0.10.0 + dart_to_js_script_rewriter: ^0.1.0+4 +transformers: +- angular2: + platform_directives: + - package:angular2/common.dart#COMMON_DIRECTIVES + platform_pipes: + - package:angular2/common.dart#COMMON_PIPES + entry_points: web/main.dart diff --git a/public/docs/_examples/toh-2/dart/web/index.html b/public/docs/_examples/toh-2/dart/web/index.html new file mode 100644 index 0000000000..059daeed4c --- /dev/null +++ b/public/docs/_examples/toh-2/dart/web/index.html @@ -0,0 +1,10 @@ + + + + + + + + Loading... + + diff --git a/public/docs/_examples/toh-2/dart/web/main.dart b/public/docs/_examples/toh-2/dart/web/main.dart new file mode 100644 index 0000000000..685cba5fce --- /dev/null +++ b/public/docs/_examples/toh-2/dart/web/main.dart @@ -0,0 +1,9 @@ +// #docregion pt2 +import 'package:angular2/bootstrap.dart'; + +import 'package:angular2_tour_of_heroes/app_component.dart'; + +main() { + bootstrap(AppComponent); +} +// #enddocregion pt2 \ No newline at end of file diff --git a/public/docs/_examples/toh-3/dart/lib/app_component.dart b/public/docs/_examples/toh-3/dart/lib/app_component.dart new file mode 100644 index 0000000000..54df64293a --- /dev/null +++ b/public/docs/_examples/toh-3/dart/lib/app_component.dart @@ -0,0 +1,102 @@ +//#docregion +import 'package:angular2/angular2.dart'; +// #docregion hero-import +import 'hero.dart'; +// #enddocregion hero-import +// #docregion hero-detail-import +import 'hero_detail_component.dart'; +// #enddocregion hero-detail-import + +@Component( + selector: 'my-app', +// #docregion hero-detail-template + template: ''' +

    {{title}}

    +

    My Heroes

    +
      +
    • + {{hero.id}} {{hero.name}} +
    • +
    + + ''', +// #enddocregion hero-detail-template + styles: const [ + ''' + .selected { + background-color: #CFD8DC !important; + color: white; + } + .heroes { + margin: 0 0 2em 0; + list-style-type: none; + padding: 0; + width: 10em; + } + .heroes li { + cursor: pointer; + position: relative; + left: 0; + background-color: #EEE; + margin: .5em; + padding: .3em 0em; + height: 1.6em; + border-radius: 4px; + } + .heroes li.selected:hover { + color: white; + } + .heroes li:hover { + color: #607D8B; + background-color: #EEE; + left: .1em; + } + .heroes .text { + position: relative; + top: -3px; + } + .heroes .badge { + display: inline-block; + font-size: small; + color: white; + padding: 0.8em 0.7em 0em 0.7em; + background-color: #607D8B; + line-height: 1em; + position: relative; + left: -1px; + top: -4px; + height: 1.8em; + margin-right: .8em; + border-radius: 4px 0px 0px 4px; + } + ''' + ], +// #docregion directives + directives: const [ + HeroDetailComponent + ]) +// #enddocregion directives +class AppComponent { + final String title = 'Tour of Heroes'; + final List heroes = mockHeroes; + Hero selectedHero; + + onSelect(Hero hero) { + selectedHero = hero; + } +} + +final List mockHeroes = [ + new Hero(11, "Mr. Nice"), + new Hero(12, "Narco"), + new Hero(13, "Bombasto"), + new Hero(14, "Celeritas"), + new Hero(15, "Magneta"), + new Hero(16, "RubberMan"), + new Hero(17, "Dynama"), + new Hero(18, "Dr IQ"), + new Hero(19, "Magma"), + new Hero(20, "Tornado") +]; diff --git a/public/docs/_examples/toh-3/dart/lib/hero.dart b/public/docs/_examples/toh-3/dart/lib/hero.dart new file mode 100644 index 0000000000..71eb336b9c --- /dev/null +++ b/public/docs/_examples/toh-3/dart/lib/hero.dart @@ -0,0 +1,8 @@ +// #docregion +class Hero { + final int id; + String name; + + Hero(this.id, this.name); +} +// #enddocregion diff --git a/public/docs/_examples/toh-3/dart/lib/hero_detail_component.dart b/public/docs/_examples/toh-3/dart/lib/hero_detail_component.dart new file mode 100644 index 0000000000..c7e1b87d52 --- /dev/null +++ b/public/docs/_examples/toh-3/dart/lib/hero_detail_component.dart @@ -0,0 +1,38 @@ +// #docplaster +// #docregion +// #docregion v1 +import 'package:angular2/core.dart'; +// #enddocregion v1 +// #docregion hero-import +import 'hero.dart'; +// #enddocregion hero-import + +// #docregion v1 +@Component( + selector: 'my-hero-detail', +// #enddocregion v1 + // #docregion template + template: ''' +
    +

    {{hero.name}} details!

    +
    {{hero.id}}
    +
    + + +
    +
    + ''', + // #enddocregion template + // #docregion inputs + inputs: const ['hero'] + // #enddocregion inputs +// #docregion v1 +) +class HeroDetailComponent { +// #enddocregion v1 +// #docregion hero + Hero hero; +// #enddocregion hero +// #docregion v1 +} +// #enddocregion v1 diff --git a/public/docs/_examples/toh-3/dart/pubspec.yaml b/public/docs/_examples/toh-3/dart/pubspec.yaml new file mode 100644 index 0000000000..ddfafde27c --- /dev/null +++ b/public/docs/_examples/toh-3/dart/pubspec.yaml @@ -0,0 +1,15 @@ +name: angular2_tour_of_heroes +version: 0.0.1 +environment: + sdk: '>=1.13.0 <2.0.0' +dependencies: + angular2: 2.0.0-beta.1 + browser: ^0.10.0 + dart_to_js_script_rewriter: ^0.1.0+4 +transformers: +- angular2: + platform_directives: + - package:angular2/common.dart#COMMON_DIRECTIVES + platform_pipes: + - package:angular2/common.dart#COMMON_PIPES + entry_points: web/main.dart diff --git a/public/docs/_examples/toh-3/dart/web/index.html b/public/docs/_examples/toh-3/dart/web/index.html new file mode 100644 index 0000000000..059daeed4c --- /dev/null +++ b/public/docs/_examples/toh-3/dart/web/index.html @@ -0,0 +1,10 @@ + + + + + + + + Loading... + + diff --git a/public/docs/_examples/toh-3/dart/web/main.dart b/public/docs/_examples/toh-3/dart/web/main.dart new file mode 100644 index 0000000000..d5b50195c1 --- /dev/null +++ b/public/docs/_examples/toh-3/dart/web/main.dart @@ -0,0 +1,9 @@ +// #docregion pt1 +import 'package:angular2/bootstrap.dart'; + +import 'package:angular2_tour_of_heroes/app_component.dart'; + +main() { + bootstrap(AppComponent); +} +// #enddocregion pt1 \ No newline at end of file diff --git a/public/docs/_examples/toh-4/dart/lib/app_component.dart b/public/docs/_examples/toh-4/dart/lib/app_component.dart new file mode 100644 index 0000000000..745d183d11 --- /dev/null +++ b/public/docs/_examples/toh-4/dart/lib/app_component.dart @@ -0,0 +1,106 @@ +// #docplaster +// #docregion +import 'dart:async'; + +import 'package:angular2/core.dart'; + +import 'hero.dart'; +import 'hero_detail_component.dart'; +// #docregion hero-service-import +import 'hero_service.dart'; + +// #enddocregion hero-service-import + +@Component( + selector: 'my-app', + template: ''' +

    {{title}}

    +

    My Heroes

    +
      +
    • + {{hero.id}} {{hero.name}} +
    • +
    + + ''', + styles: const [ + ''' + .selected { + background-color: #CFD8DC !important; + color: white; + } + .heroes { + margin: 0 0 2em 0; + list-style-type: none; + padding: 0; + width: 10em; + } + .heroes li { + cursor: pointer; + position: relative; + left: 0; + background-color: #EEE; + margin: .5em; + padding: .3em 0em; + height: 1.6em; + border-radius: 4px; + } + .heroes li.selected:hover { + color: white; + } + .heroes li:hover { + color: #607D8B; + background-color: #EEE; + left: .1em; + } + .heroes .text { + position: relative; + top: -3px; + } + .heroes .badge { + display: inline-block; + font-size: small; + color: white; + padding: 0.8em 0.7em 0em 0.7em; + background-color: #607D8B; + line-height: 1em; + position: relative; + left: -1px; + top: -4px; + height: 1.8em; + margin-right: .8em; + border-radius: 4px 0px 0px 4px; + } + ''' + ], + directives: const [ + HeroDetailComponent + ], + providers: const [ + HeroService + ]) +class AppComponent implements OnInit { + String title = 'Tour of Heroes'; + List heroes; + Hero selectedHero; + + final HeroService _heroService; + + AppComponent(this._heroService); + +// #docregion get-heroes + getHeroes() async { + heroes = await _heroService.getHeroes(); + } +// #enddocregion get-heroes + + ngOnInit() { + getHeroes(); + } + + onSelect(Hero hero) { + selectedHero = hero; + } +} diff --git a/public/docs/_examples/toh-4/dart/lib/app_component_1.dart b/public/docs/_examples/toh-4/dart/lib/app_component_1.dart new file mode 100644 index 0000000000..2f2cbb0dd0 --- /dev/null +++ b/public/docs/_examples/toh-4/dart/lib/app_component_1.dart @@ -0,0 +1,64 @@ +// #docplaster +// #docregion on-init +import 'package:angular2/core.dart'; + +// #enddocregion on-init +import 'hero.dart'; +import 'hero_detail_component.dart'; +// #docregion hero-service-import +import 'hero_service_1.dart'; +// #enddocregion hero-service-import + +// Testable but never shown +@Component( + selector: 'my-app', + template: ''' +
    + {{hero.name}} +
    + + ''', + directives: const [HeroDetailComponent], + // #docregion providers + providers: const [HeroService]) +// #enddocregion providers +// #docregion on-init +class AppComponent implements OnInit { + // #enddocregion on-init + String title = 'Tour of Heroes'; + // #docregion heroes-prop + List heroes; + // #enddocregion heroes-prop + Hero selectedHero; + + // #docregion new-service + HeroService heroService = new HeroService(); // don't do this + // #enddocregion new-service + // #docregion ctor + final HeroService _heroService; + AppComponent(this._heroService); + // #enddocregion ctor + // #docregion getHeroes + getHeroes() { + //#docregion get-heroes + heroes = _heroService.getHeroes(); + // #enddocregion get-heroes + } + // #enddocregion getHeroes + + // #docregion ng-on-init + // #docregion on-init + ngOnInit() { + // #enddocregion on-init + getHeroes(); + // #docregion on-init + } + // #enddocregion on-init + // #enddocregion ng-on-init + + onSelect(Hero hero) { + selectedHero = hero; + } + // #docregion on-init +} +// #enddocregion on-init diff --git a/public/docs/_examples/toh-4/dart/lib/hero.dart b/public/docs/_examples/toh-4/dart/lib/hero.dart new file mode 100644 index 0000000000..828f8cebab --- /dev/null +++ b/public/docs/_examples/toh-4/dart/lib/hero.dart @@ -0,0 +1,6 @@ +class Hero { + final int id; + String name; + + Hero(this.id, this.name); +} diff --git a/public/docs/_examples/toh-4/dart/lib/hero_detail_component.dart b/public/docs/_examples/toh-4/dart/lib/hero_detail_component.dart new file mode 100644 index 0000000000..5d1f76fac8 --- /dev/null +++ b/public/docs/_examples/toh-4/dart/lib/hero_detail_component.dart @@ -0,0 +1,19 @@ +import 'package:angular2/core.dart'; +import 'hero.dart'; + +@Component( + selector: 'my-hero-detail', + template: ''' +
    +

    {{hero.name}} details!

    +
    {{hero.id}}
    +
    + + +
    +
    + ''', + inputs: const ['hero']) +class HeroDetailComponent { + Hero hero; +} diff --git a/public/docs/_examples/toh-4/dart/lib/hero_service.dart b/public/docs/_examples/toh-4/dart/lib/hero_service.dart new file mode 100644 index 0000000000..4893495822 --- /dev/null +++ b/public/docs/_examples/toh-4/dart/lib/hero_service.dart @@ -0,0 +1,23 @@ +// #docplaster +// #docregion +import 'dart:async'; + +import 'package:angular2/core.dart'; + +import 'mock_heroes.dart'; +import 'hero.dart'; + +@Injectable() +class HeroService { + //#docregion get-heroes + Future> getHeroes() => new Future(() => mockHeroes); + //#enddocregion get-heroes + + // See the "Take it slow" appendix + //#docregion get-heroes-slowly + Future> getHeroesSlowly() { + return new Future.delayed(const Duration(seconds: 2), () => mockHeroes); + } + //#enddocregion get-heroes-slowly +} +// #enddocregion diff --git a/public/docs/_examples/toh-4/dart/lib/hero_service_1.dart b/public/docs/_examples/toh-4/dart/lib/hero_service_1.dart new file mode 100644 index 0000000000..76ecb2143f --- /dev/null +++ b/public/docs/_examples/toh-4/dart/lib/hero_service_1.dart @@ -0,0 +1,21 @@ +// #docplaster +// #docregion +import 'mock_heroes.dart'; +import 'hero.dart'; +// #docregion empty-class +import 'package:angular2/core.dart'; + +// #docregion getHeroes-stub +@Injectable() +class HeroService { +// #enddocregion empty-class + List getHeroes() { +// #enddocregion getHeroes-stub + return mockHeroes; +// #docregion getHeroes-stub + } +// #docregion empty-class +} +// #enddocregion getHeroes-stub +// #enddocregion empty-class +// #enddocregion \ No newline at end of file diff --git a/public/docs/_examples/toh-4/dart/lib/mock_heroes.dart b/public/docs/_examples/toh-4/dart/lib/mock_heroes.dart new file mode 100644 index 0000000000..55434761a2 --- /dev/null +++ b/public/docs/_examples/toh-4/dart/lib/mock_heroes.dart @@ -0,0 +1,16 @@ +// #docregion +import 'hero.dart'; + +final List mockHeroes = [ + new Hero(11, "Mr. Nice"), + new Hero(12, "Narco"), + new Hero(13, "Bombasto"), + new Hero(14, "Celeritas"), + new Hero(15, "Magneta"), + new Hero(16, "RubberMan"), + new Hero(17, "Dynama"), + new Hero(18, "Dr IQ"), + new Hero(19, "Magma"), + new Hero(20, "Tornado") +]; +// #enddocregion \ No newline at end of file diff --git a/public/docs/_examples/toh-4/dart/pubspec.yaml b/public/docs/_examples/toh-4/dart/pubspec.yaml new file mode 100644 index 0000000000..ddfafde27c --- /dev/null +++ b/public/docs/_examples/toh-4/dart/pubspec.yaml @@ -0,0 +1,15 @@ +name: angular2_tour_of_heroes +version: 0.0.1 +environment: + sdk: '>=1.13.0 <2.0.0' +dependencies: + angular2: 2.0.0-beta.1 + browser: ^0.10.0 + dart_to_js_script_rewriter: ^0.1.0+4 +transformers: +- angular2: + platform_directives: + - package:angular2/common.dart#COMMON_DIRECTIVES + platform_pipes: + - package:angular2/common.dart#COMMON_PIPES + entry_points: web/main.dart diff --git a/public/docs/_examples/toh-4/dart/web/index.html b/public/docs/_examples/toh-4/dart/web/index.html new file mode 100644 index 0000000000..059daeed4c --- /dev/null +++ b/public/docs/_examples/toh-4/dart/web/index.html @@ -0,0 +1,10 @@ + + + + + + + + Loading... + + diff --git a/public/docs/_examples/toh-4/dart/web/main.dart b/public/docs/_examples/toh-4/dart/web/main.dart new file mode 100644 index 0000000000..d5b50195c1 --- /dev/null +++ b/public/docs/_examples/toh-4/dart/web/main.dart @@ -0,0 +1,9 @@ +// #docregion pt1 +import 'package:angular2/bootstrap.dart'; + +import 'package:angular2_tour_of_heroes/app_component.dart'; + +main() { + bootstrap(AppComponent); +} +// #enddocregion pt1 \ No newline at end of file diff --git a/public/docs/_examples/toh-4/dart/web/main_1.dart b/public/docs/_examples/toh-4/dart/web/main_1.dart new file mode 100644 index 0000000000..c8baa39ed2 --- /dev/null +++ b/public/docs/_examples/toh-4/dart/web/main_1.dart @@ -0,0 +1,9 @@ +// #docregion pt1 +import 'package:angular2/bootstrap.dart'; + +import 'package:angular2_tour_of_heroes/app_component_1.dart'; + +main() { + bootstrap(AppComponent); +} +// #enddocregion pt1 \ No newline at end of file diff --git a/public/docs/dart/latest/_data.json b/public/docs/dart/latest/_data.json index 6cd1f36402..8c47f8c8bc 100644 --- a/public/docs/dart/latest/_data.json +++ b/public/docs/dart/latest/_data.json @@ -11,6 +11,12 @@ "title": "5 Min Quickstart" }, + "tutorial": { + "icon": "list", + "title": "Tutorial", + "banner": "Angular 2 is currently in Beta." + }, + "guide": { "icon": "list", "title": "Developers Guide", diff --git a/public/docs/dart/latest/tutorial/_data.json b/public/docs/dart/latest/tutorial/_data.json new file mode 100644 index 0000000000..d127c8f089 --- /dev/null +++ b/public/docs/dart/latest/tutorial/_data.json @@ -0,0 +1,24 @@ +{ + "_listtype": "ordered", + + "index": { + "title": "Tutorial: Tour of Heroes", + "intro": "The Tour of Heroes tutorial takes us through the steps of creating an Angular application in TypeScript." + }, + "toh-pt1": { + "title": "The Hero Editor", + "intro": "We build a simple hero editor" + }, + "toh-pt2": { + "title": "Master/Detail", + "intro": "We build a master/detail page with a list of heroes" + }, + "toh-pt3": { + "title": "Multiple Components", + "intro": "We refactor the master/detail view into separate components" + }, + "toh-pt4": { + "title": "Services", + "intro": "We create a reusable service to manage our hero data calls" + } +} \ No newline at end of file diff --git a/public/docs/dart/latest/tutorial/index.jade b/public/docs/dart/latest/tutorial/index.jade new file mode 100644 index 0000000000..89f2588cc2 --- /dev/null +++ b/public/docs/dart/latest/tutorial/index.jade @@ -0,0 +1,84 @@ +include ../../../../_includes/_util-fns + +:marked + # Tour of Heroes: the vision + + Our grand plan is to build an app to help a staffing agency manage its stable of heroes. + Even heroes need to find work. + + Of course we'll only make a little progress in this tutorial. What we do build will + have many of the features we expect to find in a full-blown, data-driven application: acquiring and displaying + a list of heroes, editing a selected hero's detail, and navigating among different + views of heroic data. + + The Tour of Heroes covers the core fundamentals of Angular. + We’ll use built-in directives to show/hide elements and display lists of hero data. + We’ll create a component to display hero details and another to show an array of heroes. + We'll use one-way data binding for read-only data. We'll add editable fields to update a model + with two-way data binding. We'll bind component method to user events like key strokes and clicks. + We’ll learn to select a hero from a master list and edit that hero in the details view. We'll + format data with pipes. We'll create a shared service to assemble our heroes. And we'll use routing to navigate among different views and their components. + + We’ll learn enough core Angular to get started and gain confidence that + Angular can do whatever we need it to do. + We'll be covering a lot of ground at an introductory level but we’ll find plenty of links + to chapters with greater depth. + + [Run the live example](https://tour-of-heroes.firebaseapp.com/toh5/) + +.l-main-section +:marked + ## The End Game + + Here's a visual idea of where we're going in this tour, beginning with the "Dashboard" + view and our most heroic heroes: + +figure.image-display + img(src='/resources/images/devguide/toh/heroes-dashboard-1.png' alt="Output of heroes dashboard") + +:marked + Above the dashboard are two links ("Dashboard" and "Heroes"). + We could click them to navigate between this Dashboard and a Heroes view. + + Instead we click the dashboard hero named "Magneta" and the router takes us to a "Hero Details" view + of that hero where we can change the hero's name. + +figure.image-display + img(src='/resources/images/devguide/toh/hero-details-1.png' alt="Details of hero in app") + +:marked + Links at the top can take us to either of the main views. + We'll click the "Back" button which sends us to the "Heroes" master list view with + "Magneta" as the selected hero. + +figure.image-display + img(src='/resources/images/devguide/toh/heroes-list-2.png' alt="Output of heroes list app") + +:marked + We click a different hero and the readonly mini-detail beneath the list reflects our new choice. + + We click the "View Details" button to drill into the + editable details of our selected hero. + + The following diagram captures all of our navigation options. + +figure.image-display + img(src='/resources/images/devguide/toh/nav-diagram.png' alt="View navigations") + +:marked + Here's our app in action + +figure.image-display + img(src='/resources/images/devguide/toh/toh-anim.gif' alt="Tour of Heroes in Action") + +.l-main-section +:marked + ## Up Next + + We’ll build this Tour of Heroes together, step by step. + We'll motivate each step with a requirement that we've + met in countless applications. Everything has a reason. + + And we’ll meet many of the core fundamentals of Angular along the way. + + [Let's get started!](./toh-pt1.html) diff --git a/public/docs/dart/latest/tutorial/toh-pt1.jade b/public/docs/dart/latest/tutorial/toh-pt1.jade new file mode 100644 index 0000000000..d5234fcc6c --- /dev/null +++ b/public/docs/dart/latest/tutorial/toh-pt1.jade @@ -0,0 +1,185 @@ +include ../../../../_includes/_util-fns + +:marked + # Once Upon a Time + + Every story starts somewhere. Our story starts where the [QuickStart](../quickstart.html) ends. + + [Run the live example for part 1](https://tour-of-heroes.firebaseapp.com/toh1/) + + Follow the "QuickStart" steps. They provide the prerequisites, the folder structure, + and the core files for our Tour of Heroes. + + + + Copy the "QuickStart" code to a new folder and rename the folder `angular2_tour_of_heroes`. + We should have the following structure: + +.filetree + .file angular2_tour_of_heroes + .children + .file lib + .children + .file app_component.dart + .file web + .children + .file index.html + .file main.dart + .file pubspec.yaml +:marked + ## Keep the app transpiling and running + We want to start the Dart compiler, have it watch for changes, and start our server. We'll do this by typing + +code-example(format="" language="bash"). + pub serve + +:marked + This command runs the compiler in watch mode, starts the server, + and keeps the app running while we continue to build the Tour of Heroes. + +.l-main-section + :marked + ## Show our Hero + We want to display Hero data in our app + + Let's add two properties to our `AppComponent`, a `title` property for the application name and a `hero` property + for a hero named "Windstorm". + + +makeExample('toh-1/dart-snippets/app_component_snippets_pt1.dart', 'app-component-1', 'app_component.dart (AppComponent class)')(format=".") + + :marked + Now we update the template in the `@Component` decoration with data bindings to these new properties. + + +makeExample('toh-1/dart-snippets/app_component_snippets_pt1.dart', 'show-hero') + + :marked + The browser should refresh and display our title and hero. + + The double curly braces tell our app to read the `title` and `hero` properties from the component and render them. + This is the "interpolation" form of one-way data binding. +.l-sub-section + :marked + Learn more about interpolation in the [Displaying Data chapter](../guide/displaying-data.html). +:marked + ### Hero object + + At the moment, our hero is just a name. Our hero needs more properties. + Let's convert the `hero` from a literal string to a class. + + Create a `Hero` class with `id` and `name` properties. + Keep this near the top of the `app_component.dart` file for now. + ++makeExample('toh-1/dart/lib/app_component.dart', 'hero-class-1', 'app_component.dart (Hero class)')(format=".") + +:marked + Now that we have a `Hero` class, let’s refactor our component’s `hero` property to be of type `Hero`. + Then initialize it with an id of `1` and the name, "Windstorm". + ++makeExample('toh-1/dart-snippets/app_component_snippets_pt1.dart', 'hero-property-1', 'app_component.dart (Hero property)')(format=".") + +:marked + Because we changed the hero from a string to an object, + we update the binding in the template to refer to the hero’s `name` property. + ++makeExample('toh-1/dart-snippets/app_component_snippets_pt1.dart', 'show-hero-2') +:marked + The browser refreshes and continues to display our hero’s name. + + ### Adding more HTML + Displaying a name is good, but we want to see all of our hero’s properties. + We’ll add a `
    ` for our hero’s `id` property and another `
    ` for our hero’s `name`. + ++makeExample('toh-1/dart-snippets/app_component_snippets_pt1.dart', 'show-hero-properties') +:marked + Uh oh, our template string is getting long. We better take care of that to avoid the risk of making a typo in the template. + + ### Multi-line template strings + + We could make a more readable template with string concatenation + but that gets ugly fast, it is harder to read, and + it is easy to make a spelling error. Instead, + let’s take advantage of the template strings feature + in Dart to maintain our sanity. + + Change the quotes around the template to triple quotes and + put the `

    `, `

    ` and `
    ` elements on their own lines. + ++makeExample('toh-1/dart-snippets/app_component_snippets_pt1.dart', 'multi-line-strings', 'app_component.dart (AppComponent\'s template)') + + .callout.is-important + header A back-tick is not a single quote + :marked + **Be careful!** A back-tick (`) looks a lot like a single quote ('). + It's actually a completely different character. + Back-ticks can do more than demarcate a string. + Here we use them in a limited way to spread the template over multiple lines. + Everything between the back-ticks at the beginning and end of the template + is part of a single template string. + +.l-main-section +:marked + ## Editing Our Hero + + We want to be able to edit the hero name in a textbox. + + Refactor the hero name `