diff --git a/public/docs/_examples/cb-barrels/ts/app/heroes/heroes.component.ts b/public/docs/_examples/cb-barrels/ts/app/heroes/heroes.component.ts
new file mode 100644
index 0000000000..6e3b2848f2
--- /dev/null
+++ b/public/docs/_examples/cb-barrels/ts/app/heroes/heroes.component.ts
@@ -0,0 +1,33 @@
+// #docregion imports
+import { Component, OnInit } from '@angular/core';
+import { Router } from '@angular/router-deprecated';
+import { HeroService, Hero } from './shared';
+import { HeroDetailComponent } from './hero-detail'
+
+@Component({
+// #enddocregion
+ selector: 'my-heroes',
+ templateUrl: 'app/heroes/heroes.component.html',
+ styleUrls: ['app/heroes/heroes.component.css'],
+ directives: [HeroDetailComponent]
+})
+export class HeroesComponent implements OnInit {
+ heroes: Hero[];
+ selectedHero: Hero;
+
+ constructor(private heroService: HeroService, private router: Router) { }
+
+ getHeroes() {
+ this.heroService.getHeroes().then(heroes => this.heroes = heroes);
+ }
+
+ gotoDetail() {
+ this.router.navigate(['HeroDetail', { id: this.selectedHero.id }]);
+ }
+
+ ngOnInit() {
+ this.getHeroes();
+ }
+
+ onSelect(hero: Hero) { this.selectedHero = hero; }
+}
diff --git a/public/docs/_examples/cb-barrels/ts/app/heroes/index.ts b/public/docs/_examples/cb-barrels/ts/app/heroes/index.ts
new file mode 100644
index 0000000000..45fa911acd
--- /dev/null
+++ b/public/docs/_examples/cb-barrels/ts/app/heroes/index.ts
@@ -0,0 +1,4 @@
+// #docregion
+export * from './hero-detail';
+export * from './heroes.component';
+export * from './shared';
diff --git a/public/docs/_examples/cb-barrels/ts/app/heroes/shared/hero.model.ts b/public/docs/_examples/cb-barrels/ts/app/heroes/shared/hero.model.ts
new file mode 100644
index 0000000000..ce714d1c00
--- /dev/null
+++ b/public/docs/_examples/cb-barrels/ts/app/heroes/shared/hero.model.ts
@@ -0,0 +1,5 @@
+export class Hero {
+ id: number;
+ name: string;
+}
+
diff --git a/public/docs/_examples/cb-barrels/ts/app/heroes/shared/hero.service.ts b/public/docs/_examples/cb-barrels/ts/app/heroes/shared/hero.service.ts
new file mode 100644
index 0000000000..11d60b97a6
--- /dev/null
+++ b/public/docs/_examples/cb-barrels/ts/app/heroes/shared/hero.service.ts
@@ -0,0 +1,17 @@
+// #docregion imports
+import { Injectable } from '@angular/core';
+import { HEROES } from './mock-heroes';
+
+@Injectable()
+export class HeroService {
+// #enddocregion
+ getHeroes() {
+ return Promise.resolve(HEROES);
+ }
+
+ getHero(id: number) {
+ return Promise.resolve(HEROES).then(
+ heroes => heroes.filter(hero => hero.id === id)[0]
+ );
+ }
+}
diff --git a/public/docs/_examples/cb-barrels/ts/app/heroes/shared/index.ts b/public/docs/_examples/cb-barrels/ts/app/heroes/shared/index.ts
new file mode 100644
index 0000000000..27516fdedd
--- /dev/null
+++ b/public/docs/_examples/cb-barrels/ts/app/heroes/shared/index.ts
@@ -0,0 +1,3 @@
+// #docregion
+export * from './hero.model';
+export * from './hero.service';
diff --git a/public/docs/_examples/cb-barrels/ts/app/heroes/shared/mock-heroes.ts b/public/docs/_examples/cb-barrels/ts/app/heroes/shared/mock-heroes.ts
new file mode 100644
index 0000000000..80d661a439
--- /dev/null
+++ b/public/docs/_examples/cb-barrels/ts/app/heroes/shared/mock-heroes.ts
@@ -0,0 +1,17 @@
+// #docregion imports
+import { Hero } from './hero.model';
+
+export var HEROES: Hero[] = [
+// #enddocregion
+
+ {"id": 11, "name": "Mr. Nice"},
+ {"id": 12, "name": "Narco"},
+ {"id": 13, "name": "Bombasto"},
+ {"id": 14, "name": "Celeritas"},
+ {"id": 15, "name": "Magneta"},
+ {"id": 16, "name": "RubberMan"},
+ {"id": 17, "name": "Dynama"},
+ {"id": 18, "name": "Dr IQ"},
+ {"id": 19, "name": "Magma"},
+ {"id": 20, "name": "Tornado"}
+];
diff --git a/public/docs/_examples/cb-barrels/ts/app/main.ts b/public/docs/_examples/cb-barrels/ts/app/main.ts
new file mode 100644
index 0000000000..09288fb174
--- /dev/null
+++ b/public/docs/_examples/cb-barrels/ts/app/main.ts
@@ -0,0 +1,11 @@
+// #docregion imports
+import { bootstrap } from '@angular/platform-browser-dynamic';
+import { ROUTER_PROVIDERS } from '@angular/router-deprecated';
+import { HeroService } from './heroes';
+import { AppComponent } from './app.component';
+
+bootstrap(AppComponent, [
+// #enddocregion
+ ROUTER_PROVIDERS,
+ HeroService
+]);
diff --git a/public/docs/_examples/cb-barrels/ts/example-config.json b/public/docs/_examples/cb-barrels/ts/example-config.json
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/public/docs/_examples/cb-barrels/ts/index.html b/public/docs/_examples/cb-barrels/ts/index.html
new file mode 100644
index 0000000000..a09ff8c91f
--- /dev/null
+++ b/public/docs/_examples/cb-barrels/ts/index.html
@@ -0,0 +1,35 @@
+
+
+
+
+ Angular 2 Tour of Heroes - Barrels
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Loading...
+
+
diff --git a/public/docs/_examples/cb-barrels/ts/plnkr.json b/public/docs/_examples/cb-barrels/ts/plnkr.json
new file mode 100644
index 0000000000..5f0eca25e7
--- /dev/null
+++ b/public/docs/_examples/cb-barrels/ts/plnkr.json
@@ -0,0 +1,8 @@
+{
+ "description": "Cookbook: Barrels",
+ "files":[
+ "!**/*.d.ts",
+ "!**/*.js"
+ ],
+ "tags": ["cookbook", "barrels"]
+}
diff --git a/public/docs/dart/latest/cookbook/_data.json b/public/docs/dart/latest/cookbook/_data.json
index 9b2545ec5e..9113b5d0ff 100644
--- a/public/docs/dart/latest/cookbook/_data.json
+++ b/public/docs/dart/latest/cookbook/_data.json
@@ -12,6 +12,12 @@
"hide": true
},
+ "barrels": {
+ "title": "Creating Barrels",
+ "intro": "Use a barrel to import from a single module that consolidate many related modules",
+ "hide": true
+ },
+
"component-communication": {
"title": "Component Interaction",
"intro": "Share information between different directives and components"
diff --git a/public/docs/dart/latest/cookbook/barrels.jade b/public/docs/dart/latest/cookbook/barrels.jade
new file mode 100644
index 0000000000..6778b6af28
--- /dev/null
+++ b/public/docs/dart/latest/cookbook/barrels.jade
@@ -0,0 +1 @@
+!= partial("../../../_includes/_ts-temp")
diff --git a/public/docs/js/latest/cookbook/_data.json b/public/docs/js/latest/cookbook/_data.json
index 2d9ada59f1..08ea9eb0b8 100644
--- a/public/docs/js/latest/cookbook/_data.json
+++ b/public/docs/js/latest/cookbook/_data.json
@@ -11,6 +11,11 @@
"intro": "Learn how Angular 1 concepts and techniques map to Angular 2"
},
+ "barrels": {
+ "title": "Creating Barrels",
+ "intro": "Use a barrel to import from a single module that consolidate many related modules"
+ },
+
"component-communication": {
"title": "Component Interaction",
"intro": "Share information between different directives and components"
diff --git a/public/docs/js/latest/cookbook/barrels.jade b/public/docs/js/latest/cookbook/barrels.jade
new file mode 100644
index 0000000000..6778b6af28
--- /dev/null
+++ b/public/docs/js/latest/cookbook/barrels.jade
@@ -0,0 +1 @@
+!= partial("../../../_includes/_ts-temp")
diff --git a/public/docs/ts/latest/cookbook/_data.json b/public/docs/ts/latest/cookbook/_data.json
index a90160de7b..b3d8131c18 100644
--- a/public/docs/ts/latest/cookbook/_data.json
+++ b/public/docs/ts/latest/cookbook/_data.json
@@ -11,6 +11,11 @@
"intro": "Learn how Angular 1 concepts and techniques map to Angular 2"
},
+ "barrels": {
+ "title": "Creating Barrels",
+ "intro": "Use a barrel to import from a single module that consolidate many related modules"
+ },
+
"component-communication": {
"title": "Component Interaction",
"intro": "Share information between different directives and components"
diff --git a/public/docs/ts/latest/cookbook/barrels.jade b/public/docs/ts/latest/cookbook/barrels.jade
new file mode 100644
index 0000000000..be113555ed
--- /dev/null
+++ b/public/docs/ts/latest/cookbook/barrels.jade
@@ -0,0 +1,106 @@
+include ../_util-fns
+
+
+:marked
+ This cookbook contains recipes for creating barrels to simplify file imports. In Angular 2 apps, we frequently find
+ ouselves importing multiple files together (for example, in the tutorial app, the hero component and the hero service
+ are both frequently imported together into other components). We can create a single export that contains them both
+ so they can be easily imported together. This is called a barrel.
+
+
+:marked
+ ## Table of contents
+
+ [Creating a barrel](#creating-a-barrel)
+
+ [Importing a barrel](#importing-a-barrel)
+
+:marked
+ **See the [live example](/resources/live-examples/cb-barrels/ts/plnkr.html)**.
+
+.l-main-section
+
+:marked
+ ## Creating a barrel
+
+ The `Hero` model, `HeroDetailComponent`, `HeroesComponent`, and `HeroService` are all frequently used together.
+ It would make things easier if we could import them all together. To make this possible, each of them
+ is moved into a `heroes` directory and organized into sub-directories with their supporting files:
+
+.filetree
+ .file heroes
+ .children
+ .file heroes.component.css
+ .file heroes.component.html
+ .file heroes.component.ts
+ .file hero-detail
+ .children
+ .file hero-detail.component.css
+ .file hero-detail.component.html
+ .file hero-detail.component.ts
+ .file shared
+ .children
+ .file hero.service.ts
+ .file hero.ts
+ .file mock-heroes.ts
+
+:marked
+ Since there are two exportable items in the shared folder, an `index.ts` file is created in that
+ folder, and then each of the files in that folder are imported and re-exported. This is our first
+ barrel. Since `mock-heroes.ts` is not used outside of the barrel it is not re-exported:
++makeExample('cb-barrels/ts/app/heroes/shared/index.ts', '', 'app/heroes/shared/index.ts')
+
+:marked
+ Even though there is only a single exportable item in the hero-detail folder, a barrel is
+ created in that folder so that all our imports are consistent, rather than some importing
+ barrels like this:
+
+ (`import { ... } from './shared'`)
+
+ and others importing files like this:
+
+ `import { ... } from './hero-detail/hero-detail.component'`
++makeExample('cb-barrels/ts/app/heroes/hero-detail/index.ts', '', 'app/heroes/hero-detail/index.ts')
+
+:marked
+ Our final barrel is in the heroes folder and it consolidates each of the other barrels into one.
+ An `index.ts` file is created in the heroes folder and then the components and barrels we just
+ created are all imported and re-exported:
++makeExample('cb-barrels/ts/app/heroes/index.ts', '', 'app/heroes/index.ts')
+
+:marked
+ The SystemJs module loader is not yet able to identify our new barrels, so
+ they are added manually as packages in index.html.
++makeExample('cb-barrels/ts/index.html', 'packages', 'index.html')
+
+:marked
+ The files inside the barrels can now be imported through a single import.
+
+
+:marked
+ ## Importing a barrel
+ The app component imports the `HeroesComponent`, `HeroDetailComponent`, and `HeroService` with a
+ single import:
++makeExample('cb-barrels/ts/app/app.component.ts', 'imports', 'app/app.component.ts')
+
+:marked
+ The dashboard component imports `Hero` and `HeroService` with a single import:
++makeExample('cb-barrels/ts/app/dashboard.component.ts', 'imports', 'app/dashboard.component.ts')
+
+:marked
+ The `main.ts` bootstrap file imports `HeroService`:
++makeExample('cb-barrels/ts/app/main.ts', 'imports', 'app/main.ts')
+
+.alert.is-helpful
+ :marked
+ Do not attempt to reference the barrel index file from within the barrel.
+ These files are still imported individually as shown below.
+
+:marked
+ The `HeroDetailComponent` is updated to import the `HeroService` and `Hero` model from the
+ `shared` barrel.
++makeExample('cb-barrels/ts/app/heroes/hero-detail/hero-detail.component.ts', 'imports', 'app/heroes/hero-detail/hero-detail.component.ts')
+
+:marked
+ And finally, the `HeroesComponent` imports the the `HeroDetailComponent` from it's barrel:
++makeExample('cb-barrels/ts/app/heroes/heroes.component.ts', 'imports', 'app/heroes/heroes.component.ts')