diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..bab156b63a --- /dev/null +++ b/.editorconfig @@ -0,0 +1,24 @@ +# http://editorconfig.org +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + + +[*.md] +max_line_length = 0 +trim_trailing_whitespace = false + +[*.jade] +max_line_length = 0 +trim_trailing_whitespace = false + +# Indentation override +#[lib/**.js] +#[{package.json,.travis.yml}] +#[**/**.js] diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index bede42df52..0000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,11 +0,0 @@ -// Place your settings in this file to overwrite default and user settings. -{ - // Controls the rendering size of tabs in characters. Accepted values: "auto", 2, 4, 6, etc. If set to "auto", the value will be guessed when a file is opened. - "editor.tabSize": 2, - // Controls if the editor will insert spaces for tabs. Accepted values: "auto", true, false. If set to "auto", the value will be guessed when a file is opened. - "editor.insertSpaces": true, - // When enabled, will trim trailing whitespace when you save a file. - "files.trimTrailingWhitespace": false, - // Specifies the folder path containing the tsserver and lib*.d.ts files to use. - "typescript.tsdk": "public/docs/_examples/node_modules/typescript/lib" -} diff --git a/gulpfile.js b/gulpfile.js index a005d1c5b8..44baa44792 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -69,12 +69,14 @@ var _excludeMatchers = _excludePatterns.map(function(excludePattern){ }); var _exampleBoilerplateFiles = [ - 'karma.conf.js', - 'karma-test-shim.js', - 'package.json', - 'styles.css', - 'tsconfig.json', - 'typings.json' + '.editorconfig', + 'karma.conf.js', + 'karma-test-shim.js', + 'package.json', + 'styles.css', + 'tsconfig.json', + 'tslint.json', + 'typings.json' ]; var _exampleDartWebBoilerPlateFiles = ['styles.css']; @@ -153,14 +155,17 @@ function findAndRunE2eTests(filter) { // to the outputFile. function runE2eTests(appDir, protractorConfigFilename, outputFile ) { // start the app - var appRunSpawnInfo = spawnExt('npm',['run','http-server', '--', '-s' ], { cwd: appDir }); - - // start protractor - var pcFilename = path.resolve(protractorConfigFilename); // need to resolve because we are going to be running from a different dir - var exePath = path.join(process.cwd(), "./node_modules/.bin/"); - var spawnInfo = spawnExt('protractor', - [ pcFilename, '--params.appDir=' + appDir, '--params.outputFile=' + outputFile], { cwd: exePath }); - return spawnInfo.promise.then(function(data) { + var appRunSpawnInfo = spawnExt('npm',['run','http-server:e2e', '--', '-s' ], { cwd: appDir }); + var tscRunSpawnInfo = spawnExt('npm',['run','tsc'], { cwd: appDir }); + + return tscRunSpawnInfo.promise.then(function(data) { + // start protractor + var pcFilename = path.resolve(protractorConfigFilename); // need to resolve because we are going to be running from a different dir + var exePath = path.join(process.cwd(), "./node_modules/.bin/"); + var spawnInfo = spawnExt('protractor', + [ pcFilename, '--params.appDir=' + appDir, '--params.outputFile=' + outputFile], { cwd: exePath }); + return spawnInfo.promise; + }).then(function(data) { // kill the app now that protractor has completed. // Ugh... proc.kill does not work properly on windows with child processes. // appRun.proc.kill(); @@ -243,14 +248,14 @@ gulp.task('add-example-boilerplate', function() { gutil.log("symlinking " + linkPath + ' -> ' + realPath) fsUtils.addSymlink(realPath, linkPath); }); - + realPath = path.join(EXAMPLES_PATH, '/typings'); var typingsPaths = getTypingsPaths(EXAMPLES_PATH); typingsPaths.forEach(function(linkPath) { - gutil.log("symlinking " + linkPath + ' -> ' + realPath) + gutil.log("symlinking " + linkPath + ' -> ' + realPath) fsUtils.addSymlink(realPath, linkPath); }); - + return copyExampleBoilerplate(); }); @@ -263,7 +268,7 @@ function copyExampleBoilerplate() { return path.join(EXAMPLES_PATH, fn); }); var examplePaths = getExamplePaths(EXAMPLES_PATH); - + var dartWebSourceFiles = _exampleDartWebBoilerPlateFiles.map(function(fn){ return path.join(EXAMPLES_PATH, fn); }); @@ -287,15 +292,15 @@ gulp.task('remove-example-boilerplate', function() { nodeModulesPaths.forEach(function(linkPath) { fsUtils.removeSymlink(linkPath); }); - + var typingsPaths = getTypingsPaths(EXAMPLES_PATH); typingsPaths.forEach(function(linkPath) { fsUtils.removeSymlink(linkPath); - }); - + }); + var examplePaths = getExamplePaths(EXAMPLES_PATH); var dartExampleWebPaths = getDartExampleWebPaths(EXAMPLES_PATH); - + return deleteFiles(_exampleBoilerplateFiles, examplePaths) .then(function() { return deleteFiles(_exampleDartWebBoilerPlateFiles, dartExampleWebPaths); @@ -346,7 +351,7 @@ gulp.task('build-js-api-docs', ['_shred-api-examples'], function() { }); gulp.task('build-plunkers', function() { - return copyExampleBoilerplate() + return copyExampleBoilerplate() .then(function() { return plunkerBuilder.buildPlunkers(EXAMPLES_PATH, LIVE_EXAMPLES_PATH, { errFn: gutil.log }); }); @@ -501,7 +506,7 @@ function harpCompile() { vars: { NODE_ENV: "production" } }); gutil.log("NODE_ENV: " + process.env.NODE_ENV); - + var deferred = Q.defer(); gutil.log('running harp compile...'); showHideExampleNodeModules('hide'); @@ -523,20 +528,20 @@ function harpCompile() { } function linkChecker(options) { - var deferred = Q.defer(); + var deferred = Q.defer(); var options = options || {}; - + var blcOptions = options.blcOptions || {}; var customData = options.customData || {}; - + var excludeBad; // don't bother reporting bad links matching this RegExp if (argv.excludeBad) { excludeBad = new RegExp(argv.excludeBad); } else { excludeBad = options.excludeBad === undefined ? /docs\/dart\/latest\/api/ : ''; } - - var previousPage; + + var previousPage; var siteUrl = argv.url || options.url || 'https://angular.io/'; // See https://github.com/stevenvachon/broken-link-checker#blcsitecheckeroptions-handlers @@ -546,12 +551,12 @@ function linkChecker(options) { //gutil.log('Scanning ' + pageUrl);docs/ts/latest/api/core/ }, junk: function(result, customData){}, - + // Analyze links link: function(result, customData){ if (!result.broken) { return; } if (excludeBad && excludeBad.test(result.url.resolved)) { return; } - + var currentPage = result.base.resolved if (previousPage !== currentPage) { previousPage = currentPage; @@ -563,10 +568,10 @@ function linkChecker(options) { //gutil.log(msg); //gutil.log(result); }, - + page: function(error, pageUrl, customData){}, site: function(error, siteUrl, customData){}, - + end: function(){ var stopTime = new Date().getTime(); var elapsed = 'Elapsed link-checking time: ' + ((stopTime - startTime)/1000) + ' seconds'; @@ -576,24 +581,24 @@ function linkChecker(options) { deferred.resolve(true); } }; - + // create an output file with header. var outputFile = path.join(process.cwd(), 'link-checker-results.txt'); var header = 'Link checker results for: ' + siteUrl + - '\nStarted: ' + (new Date()).toLocaleString() + + '\nStarted: ' + (new Date()).toLocaleString() + '\nSkipping bad links matching regex: ' +excludeBad.toString() + '\n\n'; gutil.log(header); fs.writeFileSync(outputFile, header); - + var siteChecker = new blc.SiteChecker(blcOptions, handlers); var startTime = new Date().getTime(); - - try { + + try { siteChecker.enqueue(siteUrl, customData); } catch (err) { deferred.reject(err); - } - return deferred.promise; + } + return deferred.promise; } // harp has issues with node_modules under the public dir @@ -701,7 +706,7 @@ function watchAndSync(options, cb) { env({ vars: { NODE_ENV: "production" } }); - + execCommands(['npm run harp -- server .'], {}, cb); var browserSync = require('browser-sync').create(); @@ -781,7 +786,7 @@ function apiExamplesWatch(postShredAction) { function devGuideExamplesWatch(shredOptions, postShredAction) { var includePattern = path.join(shredOptions.examplesDir, '**/*.*'); - // removed this version because gulp.watch has the same glob issue that dgeni has. + // removed this version because gulp.watch has the same glob issue that dgeni has. // var excludePattern = '!' + path.join(shredOptions.examplesDir, '**/node_modules/**/*.*'); // gulp.watch([includePattern, excludePattern], {readDelay: 500}, function (event, done) { var files = globby.sync( [includePattern], { ignore: [ '**/node_modules/**', '**/_fragments/**']}); @@ -989,7 +994,7 @@ function execCommands(cmds, options, cb) { if (!cmds || cmds.length == 0) cb(null, null, null); var exec = require('child_process').exec; // just to make it more portable. gutil.log("NODE_ENV: " + process.env.NODE_ENV); - + exec(cmds[0], options, function(err, stdout, stderr) { if (err == null) { if (options.shouldLog) { @@ -1019,4 +1024,3 @@ function checkAngularProjectPath() { throw new Error('API related tasks require the angular2 repo to be at ' + path.resolve(ANGULAR_PROJECT_PATH)); } } - diff --git a/harp.json b/harp.json index ea7c3b3a2a..be714f031d 100644 --- a/harp.json +++ b/harp.json @@ -47,6 +47,8 @@ "juleskremer": { "name": "Jules Kremer", "picture": "/resources/images/bios/juleskremer.jpg", + "twitter": "jules_kremer", + "website": "https://plus.google.com/+JulesKremer", "bio": "Jules is a TPM on the Angular team. When not working with developers, Jules is often bending into pretzel-like shapes, climbing mountains or drinking really awesome beer.", "type": "Lead" }, @@ -397,6 +399,14 @@ "website": "http://teropa.info/", "bio": "Tero is an independent software developer and writer. He's been building web applications for his whole professional career, and has almost figured out how to do vertical centering in CSS.", "type": "Community" + }, + "deborah": { + "name": "Deborah Kurata", + "picture": "/resources/images/bios/deborah.jpg", + "twitter": "deborahkurata", + "website": "http://blogs.msmvps.com/deborahk/", + "bio": "Deborah is an independent software developer and author. She is author of several Pluralsight courses including: 'Angular 2: Getting Started'", + "type": "Community" } } } diff --git a/package.json b/package.json index ece8163872..e8267dcdec 100644 --- a/package.json +++ b/package.json @@ -44,7 +44,7 @@ "gulp-task-listing": "^1.0.1", "gulp-util": "^3.0.6", "gulp-watch": "^4.3.4", - "harp": "^0.20.1", + "harp": "^0.20.3", "html2jade": "^0.8.4", "indent-string": "^2.1.0", "jasmine-core": "^2.3.4", @@ -71,5 +71,6 @@ }, "dependencies": { "jstransformer-marked": "^1.0.1" - } + }, + "homepage": "http://angular.io/" } diff --git a/public/_includes/_footer.jade b/public/_includes/_footer.jade index 394072d8ed..2fd238dc06 100644 --- a/public/_includes/_footer.jade +++ b/public/_includes/_footer.jade @@ -19,7 +19,6 @@ else ul.text-body li Angular 2.0 li Angular 1 for JS - li Angular 1 for Dart li Angular Material li AngularFire @@ -54,4 +53,4 @@ else footer(class="background-steel") small.text-caption Powered by Google ©2010-2016. Code licensed under an MIT-style License. Documentation licensed under CC BY 4.0. a(aria-label="View Style Guide" href=styleguide title="Style Guide" class="styleguide-trigger text-snow" md-button) - span.icon-favorite \ No newline at end of file + span.icon-favorite diff --git a/public/docs/_examples/.editorconfig b/public/docs/_examples/.editorconfig new file mode 100644 index 0000000000..f2abacf6d3 --- /dev/null +++ b/public/docs/_examples/.editorconfig @@ -0,0 +1,20 @@ +# http://editorconfig.org +root = true + +[*] +charset = utf-8 +indent_style = space +indent_size = 2 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + + +[*.md] +max_line_length = 0 +trim_trailing_whitespace = false + +# Indentation override +#[lib/**.js] +#[{package.json,.travis.yml}] +#[**/**.js] diff --git a/public/docs/_examples/.gitignore b/public/docs/_examples/.gitignore index 7a15251d4f..d821c82bea 100644 --- a/public/docs/_examples/.gitignore +++ b/public/docs/_examples/.gitignore @@ -1,3 +1,4 @@ +.editorconfig styles.css typings typings.json @@ -6,5 +7,6 @@ package.json karma.conf.js karma-test-shim.js tsconfig.json +tslint.json npm-debug*. **/protractor.config.js diff --git a/public/docs/_examples/architecture/dart/lib/backend_service.dart b/public/docs/_examples/architecture/dart/lib/backend_service.dart index ed425dfc82..d0f6886dbf 100644 --- a/public/docs/_examples/architecture/dart/lib/backend_service.dart +++ b/public/docs/_examples/architecture/dart/lib/backend_service.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'hero.dart'; import 'logger_service.dart'; diff --git a/public/docs/_examples/architecture/dart/lib/hero_detail_component.dart b/public/docs/_examples/architecture/dart/lib/hero_detail_component.dart index d89b4e44a8..94c26abbd0 100644 --- a/public/docs/_examples/architecture/dart/lib/hero_detail_component.dart +++ b/public/docs/_examples/architecture/dart/lib/hero_detail_component.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'hero.dart'; diff --git a/public/docs/_examples/architecture/dart/lib/hero_list_component.dart b/public/docs/_examples/architecture/dart/lib/hero_list_component.dart index 7027a01bd8..ba2b75de70 100644 --- a/public/docs/_examples/architecture/dart/lib/hero_list_component.dart +++ b/public/docs/_examples/architecture/dart/lib/hero_list_component.dart @@ -1,5 +1,5 @@ // #docplaster -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'hero.dart'; import 'hero_detail_component.dart'; diff --git a/public/docs/_examples/architecture/dart/lib/hero_service.dart b/public/docs/_examples/architecture/dart/lib/hero_service.dart index e15db5f1cd..794e79927e 100644 --- a/public/docs/_examples/architecture/dart/lib/hero_service.dart +++ b/public/docs/_examples/architecture/dart/lib/hero_service.dart @@ -1,4 +1,4 @@ -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'backend_service.dart'; import 'hero.dart'; diff --git a/public/docs/_examples/architecture/dart/lib/logger_service.dart b/public/docs/_examples/architecture/dart/lib/logger_service.dart index e1815da9a8..2d6d1c4f75 100644 --- a/public/docs/_examples/architecture/dart/lib/logger_service.dart +++ b/public/docs/_examples/architecture/dart/lib/logger_service.dart @@ -1,7 +1,7 @@ // #docregion import 'dart:html'; -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; /// A service for logging messages of various types. /// diff --git a/public/docs/_examples/architecture/dart/pubspec.yaml b/public/docs/_examples/architecture/dart/pubspec.yaml index 9466bdac16..9be156cfc7 100644 --- a/public/docs/_examples/architecture/dart/pubspec.yaml +++ b/public/docs/_examples/architecture/dart/pubspec.yaml @@ -5,9 +5,9 @@ version: 0.0.1 environment: sdk: '>=1.13.0 <2.0.0' dependencies: - angular2: 2.0.0-beta.11 + angular2: 2.0.0-beta.13.1 browser: ^0.10.0 - dart_to_js_script_rewriter: ^0.1.0 + dart_to_js_script_rewriter: ^1.0.1 transformers: - angular2: platform_directives: 'package:angular2/common.dart#CORE_DIRECTIVES' diff --git a/public/docs/_examples/architecture/dart/web/main.dart b/public/docs/_examples/architecture/dart/web/main.dart index c96db07bb8..acb382ab8e 100644 --- a/public/docs/_examples/architecture/dart/web/main.dart +++ b/public/docs/_examples/architecture/dart/web/main.dart @@ -1,5 +1,6 @@ // #docregion -import 'package:angular2/bootstrap.dart'; +import 'package:angular2/platform/browser.dart'; + import 'package:developer_guide_intro/backend_service.dart'; import 'package:developer_guide_intro/hero_list_component.dart'; import 'package:developer_guide_intro/hero_service.dart'; diff --git a/public/docs/_examples/attribute-directives/dart/lib/app_component.dart b/public/docs/_examples/attribute-directives/dart/lib/app_component.dart index 0d3ad7595b..2494fc3fd7 100644 --- a/public/docs/_examples/attribute-directives/dart/lib/app_component.dart +++ b/public/docs/_examples/attribute-directives/dart/lib/app_component.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'highlight_directive.dart'; diff --git a/public/docs/_examples/attribute-directives/dart/lib/highlight_directive.dart b/public/docs/_examples/attribute-directives/dart/lib/highlight_directive.dart index 0fb5832160..a6c0856cc4 100644 --- a/public/docs/_examples/attribute-directives/dart/lib/highlight_directive.dart +++ b/public/docs/_examples/attribute-directives/dart/lib/highlight_directive.dart @@ -1,6 +1,6 @@ // #docplaster // #docregion full -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; @Directive(selector: '[my-highlight]', host: const { '(mouseenter)': 'onMouseEnter()', diff --git a/public/docs/_examples/attribute-directives/dart/lib/highlight_directive_1.dart b/public/docs/_examples/attribute-directives/dart/lib/highlight_directive_1.dart index 4fef486203..3b79e66a3b 100644 --- a/public/docs/_examples/attribute-directives/dart/lib/highlight_directive_1.dart +++ b/public/docs/_examples/attribute-directives/dart/lib/highlight_directive_1.dart @@ -1,7 +1,7 @@ // #docregion library attribute_directives.highlight_directive; -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; @Directive(selector: '[my-highlight]') class Highlight { diff --git a/public/docs/_examples/attribute-directives/dart/lib/highlight_directive_2.dart b/public/docs/_examples/attribute-directives/dart/lib/highlight_directive_2.dart index 1561af0535..8c540b3a6a 100644 --- a/public/docs/_examples/attribute-directives/dart/lib/highlight_directive_2.dart +++ b/public/docs/_examples/attribute-directives/dart/lib/highlight_directive_2.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; @Directive(selector: '[my-highlight]', // #docregion host diff --git a/public/docs/_examples/attribute-directives/dart/pubspec.yaml b/public/docs/_examples/attribute-directives/dart/pubspec.yaml index 25f96209c1..897e7dd174 100644 --- a/public/docs/_examples/attribute-directives/dart/pubspec.yaml +++ b/public/docs/_examples/attribute-directives/dart/pubspec.yaml @@ -5,9 +5,9 @@ version: 0.0.1 environment: sdk: '>=1.13.0 <2.0.0' dependencies: - angular2: 2.0.0-beta.11 + angular2: 2.0.0-beta.13.1 browser: ^0.10.0 - dart_to_js_script_rewriter: ^0.1.0 + dart_to_js_script_rewriter: ^1.0.1 transformers: - angular2: platform_directives: 'package:angular2/common.dart#CORE_DIRECTIVES' diff --git a/public/docs/_examples/attribute-directives/dart/web/main.dart b/public/docs/_examples/attribute-directives/dart/web/main.dart index ce74487a47..0703b7ab25 100644 --- a/public/docs/_examples/attribute-directives/dart/web/main.dart +++ b/public/docs/_examples/attribute-directives/dart/web/main.dart @@ -1,5 +1,6 @@ // #docregion -import 'package:angular2/bootstrap.dart'; +import 'package:angular2/platform/browser.dart'; + import 'package:attribute_directives/app_component.dart'; main() { diff --git a/public/docs/_examples/attribute-directives/ts/app/highlight.directive.2.ts b/public/docs/_examples/attribute-directives/ts/app/highlight.directive.2.ts index 9cf0b95970..1f42c5773f 100644 --- a/public/docs/_examples/attribute-directives/ts/app/highlight.directive.2.ts +++ b/public/docs/_examples/attribute-directives/ts/app/highlight.directive.2.ts @@ -12,8 +12,10 @@ import {Directive, ElementRef, Input} from 'angular2/core'; }) export class HighlightDirective { + // #docregion ctor - constructor(private el: ElementRef) { } + private _el:HTMLElement; + constructor(el: ElementRef) { this._el = el.nativeElement; } // #enddocregion ctor // #docregion mouse-methods @@ -21,7 +23,7 @@ export class HighlightDirective { onMouseLeave() { this._highlight(null); } private _highlight(color: string) { - this.el.nativeElement.style.backgroundColor = color; + this._el.style.backgroundColor = color; } // #enddocregion mouse-methods diff --git a/public/docs/_examples/attribute-directives/ts/app/highlight.directive.ts b/public/docs/_examples/attribute-directives/ts/app/highlight.directive.ts index 6a26780057..4380174c8f 100644 --- a/public/docs/_examples/attribute-directives/ts/app/highlight.directive.ts +++ b/public/docs/_examples/attribute-directives/ts/app/highlight.directive.ts @@ -12,6 +12,9 @@ import {Directive, ElementRef, Input} from 'angular2/core'; // #docregion class-1 export class HighlightDirective { + + private _defaultColor = 'red'; + private _el:HTMLElement; // #enddocregion class-1 // #enddocregion full /* @@ -20,21 +23,21 @@ export class HighlightDirective { // #enddocregion highlight */ // #docregion full + +// #docregion defaultColor + @Input() set defaultColor(colorName:string){ + this._defaultColor = colorName || this._defaultColor; + } +// #enddocregion defaultColor // #docregion class-1 + // #docregion color @Input('myHighlight') highlightColor: string; // #enddocregion color - private _defaultColor = 'red'; // #enddocregion class-1 - // #docregion defaultColor - @Input() set defaultColor(colorName:string){ - this._defaultColor = colorName || this._defaultColor; - } - // #enddocregion defaultColor // #docregion class-1 - - constructor(private el: ElementRef) { } + constructor(el: ElementRef) { this._el = el.nativeElement; } // #docregion mouse-enter onMouseEnter() { this._highlight(this.highlightColor || this._defaultColor); } @@ -42,7 +45,7 @@ export class HighlightDirective { onMouseLeave() { this._highlight(null); } private _highlight(color:string) { - this.el.nativeElement.style.backgroundColor = color; + this._el.style.backgroundColor = color; } } // #enddocregion class-1 diff --git a/public/docs/_examples/cb-component-communication/ts/app/hero.ts b/public/docs/_examples/cb-component-communication/ts/app/hero.ts index 5b99f17132..16ce60d8ed 100644 --- a/public/docs/_examples/cb-component-communication/ts/app/hero.ts +++ b/public/docs/_examples/cb-component-communication/ts/app/hero.ts @@ -1,4 +1,4 @@ -export interface Hero { +export class Hero { name: string; } diff --git a/public/docs/_examples/cb-dependency-injection/e2e-spec.js b/public/docs/_examples/cb-dependency-injection/e2e-spec.js new file mode 100644 index 0000000000..aeb0e68b17 --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/e2e-spec.js @@ -0,0 +1,98 @@ +describe('Dependency Injection Cookbook', function () { + + beforeAll(function () { + browser.get(''); + }); + + it('should render Logged in User example', function () { + var loggedInUser = element.all(by.xpath('//h3[text()="Logged in user"]')).get(0); + expect(loggedInUser).toBeDefined(); + }); + + it('"Bombasto" should be the logged in user', function () { + loggedInUser = element.all(by.xpath('//div[text()="Name: Bombasto"]')).get(0); + expect(loggedInUser).toBeDefined(); + }); + + it('should render sorted heroes', function () { + var sortedHeroes = element.all(by.xpath('//h3[text()="Sorted Heroes" and position()=1]')).get(0); + expect(sortedHeroes).toBeDefined(); + }); + + it('Mr. Nice should be in sorted heroes', function () { + var sortedHero = element.all(by.xpath('//sorted-heroes/[text()="Mr. Nice" and position()=2]')).get(0); + expect(sortedHero).toBeDefined(); + }); + + it('RubberMan should be in sorted heroes', function () { + sortedHero = element.all(by.xpath('//sorted-heroes/[text()="RubberMan" and position()=3]')).get(0); + expect(sortedHero).toBeDefined(); + }); + + it('Magma should be in sorted heroes', function () { + sortedHero = element.all(by.xpath('//sorted-heroes/[text()="Magma"]')).get(0); + expect(sortedHero).toBeDefined(); + }); + + it('should render Hero of the Month', function () { + var heroOfTheMonth = element.all(by.xpath('//h3[text()="Hero of the month"]')).get(0); + expect(heroOfTheMonth).toBeDefined(); + }); + + it('should render Hero Bios', function () { + var heroBios = element.all(by.xpath('//h3[text()="Hero Bios"]')).get(0); + expect(heroBios).toBeDefined(); + }); + + it('should render Magma\'s description in Hero Bios', function () { + var magmaText = element.all(by.xpath('//textarea[text()="Hero of all trades"]')).get(0); + expect(magmaText).toBeDefined(); + }); + + it('should render Magma\'s phone in Hero Bios and Contacts', function () { + var magmaPhone = element.all(by.xpath('//div[text()="Phone #: 555-555-5555"]')).get(0); + expect(magmaPhone).toBeDefined(); + }); + + it('should render Hero-of-the-Month runner-ups', function () { + var runnersUp = element(by.id('rups')).getText(); + expect(runnersUp).toContain('RubberMan, Mr. Nice'); + }); + + it('should render DateLogger log entry in Hero-of-the-Month', function () { + var logs = element.all(by.id('logs')).get(0).getText(); + expect(logs).toContain('INFO: starting up at'); + }); + + it('should highlight Hero Bios and Contacts container when mouseover', function () { + var target = element(by.css('div[myHighlight="yellow"]')) + var yellow = "rgba(255, 255, 0, 1)"; + + expect(target.getCssValue('background-color')).not.toEqual(yellow); + browser.actions().mouseMove(target).perform(); + expect(target.getCssValue('background-color')).toEqual(yellow); + }); + + describe('in Parent Finder', function () { + var cathy1 = element(by.css('alex cathy')); + var craig1 = element(by.css('alex craig')); + var carol1 = element(by.css('alex carol p')); + var carol2 = element(by.css('barry carol p')); + + it('"Cathy" should find "Alex" via the component class', function () { + expect(cathy1.getText()).toContain('Found Alex via the component'); + }); + + it('"Craig" should not find "Alex" via the base class', function () { + expect(craig1.getText()).toContain('Did not find Alex via the base'); + }); + + it('"Carol" within "Alex" should have "Alex" parent', function () { + expect(carol1.getText()).toContain('Alex'); + }); + + it('"Carol" within "Barry" should have "Barry" parent', function () { + expect(carol2.getText()).toContain('Barry'); + }); + }) +}); diff --git a/public/docs/_examples/cb-dependency-injection/ts/.gitignore b/public/docs/_examples/cb-dependency-injection/ts/.gitignore new file mode 100644 index 0000000000..cf44e148ba --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/.gitignore @@ -0,0 +1 @@ +**/*.js \ No newline at end of file diff --git a/public/docs/_examples/cb-dependency-injection/ts/app/app.component.html b/public/docs/_examples/cb-dependency-injection/ts/app/app.component.html new file mode 100644 index 0000000000..c27281f2af --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/app/app.component.html @@ -0,0 +1,39 @@ +

DI Cookbook

+
+

Logged in user

+
Name: {{userContext.name}}
+
Role: {{userContext.role}}
+
+ +
+

Hero Bios

+ +
+ + +
+

Hero Bios and Contacts

+
+ +
+
+ + +
+ +
+ + +
+

Unsorted Heroes

+ +
+ +
+

Sorted Heroes

+ +
+ +
+ +
\ No newline at end of file diff --git a/public/docs/_examples/cb-dependency-injection/ts/app/app.component.ts b/public/docs/_examples/cb-dependency-injection/ts/app/app.component.ts new file mode 100644 index 0000000000..2e4485f665 --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/app/app.component.ts @@ -0,0 +1,46 @@ +// #docregion +import { Component } from 'angular2/core'; + +import { HeroBiosComponent, + HeroBiosAndContactsComponent} from './hero-bios.component'; +import { HeroOfTheMonthComponent } from './hero-of-the-month.component'; +import { HeroesBaseComponent, + SortedHeroesComponent } from './sorted-heroes.component'; +import { HighlightDirective } from './highlight.directive'; +import { ParentFinderComponent } from './parent-finder.component'; + +const DIRECTIVES = [ + HeroBiosComponent, HeroBiosAndContactsComponent, + HeroesBaseComponent, SortedHeroesComponent, + HeroOfTheMonthComponent, + HighlightDirective, + ParentFinderComponent +]; + +// #docregion import-services +import { LoggerService } from './logger.service'; +import { UserContextService } from './user-context.service'; +import { UserService } from './user.service'; + +@Component({ + selector: 'my-app', + templateUrl:'app/app.component.html', + directives: DIRECTIVES, +// #docregion providers + providers: [LoggerService, UserContextService, UserService] +// #enddocregion providers +}) +export class AppComponent { +// #enddocregion import-services + + private userId:number = 1; + + // #docregion ctor + constructor(logger:LoggerService, public userContext:UserContextService) { + userContext.loadUser(this.userId); + logger.logInfo('AppComponent initialized'); + } + // #enddocregion ctor +// #docregion import-services +} +// #enddocregion import-services diff --git a/public/docs/_examples/cb-dependency-injection/ts/app/date-logger.service.ts b/public/docs/_examples/cb-dependency-injection/ts/app/date-logger.service.ts new file mode 100644 index 0000000000..125ba37c2b --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/app/date-logger.service.ts @@ -0,0 +1,37 @@ +/* tslint:disable:one-line:check-open-brace*/ +// #docregion +import { Injectable } from 'angular2/core'; +import { LoggerService } from './logger.service'; + +// #docregion minimal-logger +// class used as a restricting interface (hides other public members) +export abstract class MinimalLogger { + logInfo: (msg: string) => void; + logs: string[]; +} +// #enddocregion minimal-logger + +/* +// Transpiles to: +// #docregion minimal-logger-transpiled + var MinimalLogger = (function () { + function MinimalLogger() {} + return MinimalLogger; + }()); + exports("MinimalLogger", MinimalLogger); +// #enddocregion minimal-logger-transpiled + */ + +// #docregion date-logger-service +@Injectable() +// #docregion date-logger-service-signature +export class DateLoggerService extends LoggerService implements MinimalLogger +// #enddocregion date-logger-service-signature +{ + logInfo(msg: any) { super.logInfo(stamp(msg)); } + logDebug(msg: any) { super.logInfo(stamp(msg)); } + logError(msg: any) { super.logError(stamp(msg)); } +} + +function stamp(msg: any) { return msg + ' at ' + new Date(); } +// #enddocregion date-logger-service diff --git a/public/docs/_examples/cb-dependency-injection/ts/app/hero-bio.component.ts b/public/docs/_examples/cb-dependency-injection/ts/app/hero-bio.component.ts new file mode 100644 index 0000000000..6b006fcc56 --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/app/hero-bio.component.ts @@ -0,0 +1,29 @@ +// #docregion +import {Component, Input, OnInit} from 'angular2/core'; + +import {Hero} from './hero'; +import {HeroCacheService} from './hero-cache.service'; + +// #docregion component +@Component({ + selector:'hero-bio', + // #docregion template + template:` +

{{hero.name}}

+ + `, + // #enddocregion template + providers: [HeroCacheService] +}) + +export class HeroBioComponent implements OnInit { + + @Input() heroId:number; + + constructor(private _heroCache:HeroCacheService) { } + + ngOnInit() { this._heroCache.fetchCachedHero(this.heroId); } + + get hero() { return this._heroCache.hero; } +} +// #enddocregion component diff --git a/public/docs/_examples/cb-dependency-injection/ts/app/hero-bios.component.ts b/public/docs/_examples/cb-dependency-injection/ts/app/hero-bios.component.ts new file mode 100644 index 0000000000..9d14daf648 --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/app/hero-bios.component.ts @@ -0,0 +1,52 @@ +// #docplaster +// #docregion +import { Component} from 'angular2/core'; + +import { HeroContactComponent } from './hero-contact.component'; +import { HeroBioComponent } from './hero-bio.component'; +import { HeroService } from './hero.service'; +import { LoggerService } from './logger.service'; + +//////// HeroBiosComponent //// +// #docregion simple +@Component({ + selector:'hero-bios', + template:` + + + `, + directives:[HeroBioComponent], + providers: [HeroService] +}) +export class HeroBiosComponent{ +// #enddocregion simple +// #docregion ctor + constructor(logger: LoggerService) { + logger.logInfo('Creating HeroBiosComponent'); + } +// #enddocregion ctor +// #docregion simple +} +// #enddocregion simple + +//////// HeroBiosAndContactsComponent //// +// #docregion hero-bios-and-contacts +@Component({ + selector:'hero-bios-and-contacts', + // #docregion template + template:` + + + `, + // #enddocregion template + directives:[HeroBioComponent, HeroContactComponent], + // #docregion class-provider + providers: [HeroService] + // #enddocregion class-provider +}) +export class HeroBiosAndContactsComponent{ + constructor(logger: LoggerService) { + logger.logInfo('Creating HeroBiosAndContactsComponent'); + } +} +// #enddocregion hero-bios-and-contacts \ No newline at end of file diff --git a/public/docs/_examples/cb-dependency-injection/ts/app/hero-cache.service.ts b/public/docs/_examples/cb-dependency-injection/ts/app/hero-cache.service.ts new file mode 100644 index 0000000000..c0c7ce581f --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/app/hero-cache.service.ts @@ -0,0 +1,19 @@ +// #docregion +import {Injectable} from 'angular2/core'; +import {Hero} from './hero'; +import {HeroService} from './hero.service'; + +// #docregion service +@Injectable() +export class HeroCacheService { + hero:Hero; + constructor(private _heroService:HeroService){} + + fetchCachedHero(id:number){ + if (!this.hero) { + this.hero = this._heroService.getHeroById(id); + } + return this.hero + } +} +// #enddocregion service diff --git a/public/docs/_examples/cb-dependency-injection/ts/app/hero-contact.component.ts b/public/docs/_examples/cb-dependency-injection/ts/app/hero-contact.component.ts new file mode 100644 index 0000000000..42163d3f3e --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/app/hero-contact.component.ts @@ -0,0 +1,39 @@ +// #docplaster +// #docregion +import {Component, ElementRef, Host, Inject, Optional} from 'angular2/core'; +import {HeroCacheService} from './hero-cache.service'; +import {LoggerService} from './logger.service'; + +// #docregion component +@Component({ + selector:'hero-contact', + template:` +
Phone #: {{phoneNumber}} + !!!
` +}) +export class HeroContactComponent { + + hasLogger = false; + + constructor( + // #docregion ctor-params + @Host() // limit to the host component's instance of the HeroCacheService + private _heroCache: HeroCacheService, + + @Host() // limit search for logger; hides the application-wide logger + @Optional() // ok if the logger doesn't exist + private _loggerService: LoggerService + // #enddocregion ctor-params + ) { + if (_loggerService) { + this.hasLogger = true; + _loggerService.logInfo('HeroContactComponent can log!'); + } + // #docregion ctor + } + // #enddocregion ctor + + get phoneNumber() { return this._heroCache.hero.phone; } + +} +// #enddocregion component diff --git a/public/docs/_examples/cb-dependency-injection/ts/app/hero-data.ts b/public/docs/_examples/cb-dependency-injection/ts/app/hero-data.ts new file mode 100644 index 0000000000..18133fd771 --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/app/hero-data.ts @@ -0,0 +1,14 @@ +// #docregion +import {Hero} from './hero'; + +export class HeroData { + createDb() { + let heroes = [ + new Hero(1,"Windstorm"), + new Hero(2,"Bombasto"), + new Hero(3,"Magneta"), + new Hero(4,"Tornado") + ]; + return {heroes}; + } +} diff --git a/public/docs/_examples/cb-dependency-injection/ts/app/hero-of-the-month.component.ts b/public/docs/_examples/cb-dependency-injection/ts/app/hero-of-the-month.component.ts new file mode 100644 index 0000000000..02dcae4824 --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/app/hero-of-the-month.component.ts @@ -0,0 +1,75 @@ +/* tslint:disable:one-line:check-open-brace*/ +// #docplaster +// #docregion opaque-token +import {OpaqueToken} from 'angular2/core'; + +export const TITLE = new OpaqueToken('title'); +// #enddocregion opaque-token + +// #docregion hero-of-the-month +import { Component, Inject, provide } from 'angular2/core'; + +import { DateLoggerService, + MinimalLogger } from './date-logger.service'; +import { Hero } from './hero'; +import { HeroService } from './hero.service'; +import { LoggerService } from './logger.service'; +import { RUNNERS_UP, + runnersUpFactory } from './runners-up'; + +// #enddocregion hero-of-the-month +// #docregion some-hero +const someHero = new Hero(42, 'Magma', 'Had a great month!', '555-555-5555'); +// #enddocregion some-hero + +const template = ` +

{{title}}

+
Winner: {{heroOfTheMonth.name}}
+
Reason for award: {{heroOfTheMonth.description}}
+
Runners-up: {{runnersUp}}
+ +

Logs:

+
+
{{log}}
+
+ `; + +// #docregion hero-of-the-month +@Component({ + selector: 'hero-of-the-month', + template: template, + providers: [ + // #docregion use-value + provide(Hero, {useValue: someHero}), + // #docregion provide-opaque-token + provide(TITLE, {useValue: 'Hero of the Month'}), + // #enddocregion provide-opaque-token + // #enddocregion use-value + // #docregion use-class + provide(HeroService, {useClass: HeroService}), + provide(LoggerService, {useClass: DateLoggerService}), + // #enddocregion use-class + // #docregion use-existing + provide(MinimalLogger, {useExisting: LoggerService}), + // #enddocregion use-existing + // #docregion provide-opaque-token, use-factory + provide(RUNNERS_UP, {useFactory: runnersUpFactory(2), deps: [Hero, HeroService]}) + // #enddocregion provide-opaque-token, use-factory + ] +}) +export class HeroOfTheMonthComponent { + logs: string[] = []; + +// #docregion ctor-signature + constructor( + logger: MinimalLogger, + public heroOfTheMonth: Hero, + @Inject(RUNNERS_UP) public runnersUp: string, + @Inject(TITLE) public title: string) +// #enddocregion ctor-signature + { + this.logs = logger.logs; + logger.logInfo('starting up'); + } +} +// #enddocregion hero-of-the-month diff --git a/public/docs/_examples/cb-dependency-injection/ts/app/hero.service.ts b/public/docs/_examples/cb-dependency-injection/ts/app/hero.service.ts new file mode 100644 index 0000000000..274753ae8d --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/app/hero.service.ts @@ -0,0 +1,22 @@ +// #docregion +import {Injectable} from 'angular2/core'; +import {Hero} from './hero'; + +@Injectable() +export class HeroService { + + //TODO move to database + private _heros:Array = [ + new Hero(1, 'RubberMan','Hero of many talents', '123-456-7899'), + new Hero(2, 'Magma','Hero of all trades', '555-555-5555'), + new Hero(3, 'Mr. Nice','The name says it all','111-222-3333') + ]; + + getHeroById(id:number):Hero{ + return this._heros.filter(hero => hero.id === id)[0]; + } + + getAllHeroes():Array{ + return this._heros; + } +} \ No newline at end of file diff --git a/public/docs/_examples/cb-dependency-injection/ts/app/hero.ts b/public/docs/_examples/cb-dependency-injection/ts/app/hero.ts new file mode 100644 index 0000000000..51ce8ebbff --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/app/hero.ts @@ -0,0 +1,9 @@ +// #docregion +export class Hero{ + constructor( + public id: number, + public name:string, + public description?:string, + public phone?:string) { + } +} \ No newline at end of file diff --git a/public/docs/_examples/cb-dependency-injection/ts/app/highlight.directive.ts b/public/docs/_examples/cb-dependency-injection/ts/app/highlight.directive.ts new file mode 100644 index 0000000000..6d054e1a0b --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/app/highlight.directive.ts @@ -0,0 +1,28 @@ +// #docplaster +// #docregion +import {Directive, ElementRef, Input} from 'angular2/core'; + +@Directive({ + selector: '[myHighlight]', + host: { + '(mouseenter)': 'onMouseEnter()', + '(mouseleave)': 'onMouseLeave()' + } +}) +export class HighlightDirective { + + @Input('myHighlight') highlightColor: string; + + private _el: HTMLElement; + + constructor(el: ElementRef) { + this._el = el.nativeElement; + } + + onMouseEnter() { this._highlight(this.highlightColor || 'cyan'); } + onMouseLeave() { this._highlight(null); } + + private _highlight(color: string) { + this._el.style.backgroundColor = color; + } +} diff --git a/public/docs/_examples/cb-dependency-injection/ts/app/logger.service.ts b/public/docs/_examples/cb-dependency-injection/ts/app/logger.service.ts new file mode 100644 index 0000000000..ecc75350e3 --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/app/logger.service.ts @@ -0,0 +1,16 @@ +// #docregion +import {Injectable} from 'angular2/core'; + +@Injectable() +export class LoggerService { + logs: string[] = []; + + logInfo(msg: any) { this.log(`INFO: ${msg}`); } + logDebug(msg: any) { this.log(`DEBUG: ${msg}`); } + logError(msg: any) { this.log(`ERROR: ${msg}`, true); } + + private log(msg: any, isErr = false) { + this.logs.push(msg); + isErr ? console.error(msg) : console.log(msg); + } +} diff --git a/public/docs/_examples/cb-dependency-injection/ts/app/main.ts b/public/docs/_examples/cb-dependency-injection/ts/app/main.ts new file mode 100644 index 0000000000..b1e35e2a67 --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/app/main.ts @@ -0,0 +1,25 @@ +// #docregion +import { bootstrap } from 'angular2/platform/browser'; +import { provide } from 'angular2/core'; +import { XHRBackend } from 'angular2/http'; + +import { LocationStrategy, + HashLocationStrategy, + ROUTER_PROVIDERS } from 'angular2/router'; + +import { HeroData } from './hero-data'; +import { InMemoryBackendService, + SEED_DATA } from 'a2-in-memory-web-api/core'; + +import { AppComponent } from './app.component'; + +// #docregion bootstrap +bootstrap(AppComponent, [ + ROUTER_PROVIDERS, + provide(LocationStrategy, + {useClass: HashLocationStrategy}), + + provide(XHRBackend, { useClass: InMemoryBackendService }), // in-mem server + provide(SEED_DATA, { useClass: HeroData }) // in-mem server data +]).catch((err: any) => console.error(err)); +// #enddocregion bootstrap diff --git a/public/docs/_examples/cb-dependency-injection/ts/app/parent-finder.component.ts b/public/docs/_examples/cb-dependency-injection/ts/app/parent-finder.component.ts new file mode 100644 index 0000000000..4099ec6af9 --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/app/parent-finder.component.ts @@ -0,0 +1,227 @@ +/* tslint:disable:no-unused-variable */ +/* tslint:disable:one-line:check-open-brace*/ +// #docplaster +// #docregion +import { Component, forwardRef, Optional, provide, SkipSelf } from 'angular2/core'; + +// A component base class (see AlexComponent) +export abstract class Base { name = 'Count Basie'; } + +// Marker class, used as an interface +// #docregion parent +export abstract class Parent { name: string; } +// #enddocregion parent + +const DifferentParent = Parent; + +// #docregion provide-parent, provide-the-parent +// Helper method to provide the current component instance in the name of a `parentType`. +// #enddocregion provide-the-parent +// The `parentType` defaults to `Parent` when omitting the second parameter. +// #docregion provide-the-parent +const provideParent = +// #enddocregion provide-parent, provide-the-parent +// #docregion provide-parent + (component: any, parentType?: any) => + provide(parentType || Parent, { useExisting: forwardRef(() => component) }); +// #enddocregion provide-parent + +// Simpler syntax version that always provides the component in the name of `Parent`. +const provideTheParent = +// #docregion provide-the-parent + (component: any) => provide(Parent, { useExisting: forwardRef(() => component) }); +// #enddocregion provide-the-parent + + +///////// C - Child ////////// +// #docregion carol +const templateC = ` +
+

{{name}}

+

My parent is {{parent?.name}}

+
`; + +@Component({ + selector: 'carol', + template: templateC +}) +// #docregion carol-class +export class CarolComponent { + name= 'Carol'; + // #docregion carol-ctor + constructor( @Optional() public parent: Parent ) { } + // #enddocregion carol-ctor +} +// #enddocregion carol-class +// #enddocregion carol + +@Component({ + selector: 'chris', + template: templateC +}) +export class ChrisComponent { + name= 'Chris'; + constructor( @Optional() public parent: Parent ) { } +} + +////// Craig /////////// +/** + * Show we cannot inject a parent by its base class. + */ +// #docregion craig +@Component({ + selector: 'craig', + template: ` +
+

Craig

+ {{alex ? 'Found' : 'Did not find'}} Alex via the base class. +
` +}) +export class CraigComponent { + constructor( @Optional() public alex: Base ) { } +} +// #enddocregion craig + +// #docregion C_DIRECTIVES +const C_DIRECTIVES = [ + CarolComponent, ChrisComponent, CraigComponent, + forwardRef(() => CathyComponent) +]; +// #enddocregion C_DIRECTIVES + +//////// B - Parent ///////// +// #docregion barry +const templateB = ` +
+
+

{{name}}

+

My parent is {{parent?.name}}

+
+ + +
`; + +@Component({ + selector: 'barry', + template: templateB, + directives: C_DIRECTIVES, + providers: [ provide(Parent, { useExisting: forwardRef(() => BarryComponent) }) ] +}) +export class BarryComponent implements Parent { + name = 'Barry'; +// #docregion barry-ctor + constructor( @SkipSelf() @Optional() public parent: Parent ) { } +// #enddocregion barry-ctor +} +// #enddocregion barry + +@Component({ + selector: 'bob', + template: templateB, + directives: C_DIRECTIVES, + providers: [ provideParent(BobComponent) ] +}) +export class BobComponent implements Parent { + name= 'Bob'; + constructor( @SkipSelf() @Optional() public parent: Parent ) { } +} + +@Component({ + selector: 'beth', + template: templateB, + directives: C_DIRECTIVES, +// #docregion beth-providers + providers: [ provideParent(BethComponent, DifferentParent) ] +// #enddocregion beth-providers +}) +export class BethComponent implements Parent { + name= 'Beth'; + constructor( @SkipSelf() @Optional() public parent: Parent ) { } +} + +const B_DIRECTIVES = [ BarryComponent, BethComponent, BobComponent ]; + +///////// A - Grandparent ////// + +// #docregion alex, alex-1 +@Component({ + selector: 'alex', + template: ` +
+

{{name}}

+ + + +
`, +// #enddocregion alex-1 +// #docregion alex-providers + providers: [ provide(Parent, { useExisting: forwardRef(() => AlexComponent) }) ], +// #enddocregion alex-providers +// #docregion alex-1 + directives: C_DIRECTIVES +}) +// #enddocregion alex-1 +// Todo: Add `... implements Parent` to class signature +// #docregion alex-1 +// #docregion alex-class-signature +export class AlexComponent extends Base +// #enddocregion alex-class-signature +{ + name= 'Alex'; +} +// #enddocregion alex, alex-1 + +///// + +// #docregion alice +@Component({ + selector: 'alice', + template: ` +
+

{{name}}

+ + + + +
`, + directives: [ B_DIRECTIVES, C_DIRECTIVES ], +// #docregion alice-providers + providers: [ provideParent(AliceComponent) ] +// #enddocregion alice-providers +}) +// #docregion alice-class-signature +export class AliceComponent implements Parent +// #enddocregion alice-class-signature +{ + name= 'Alice'; +} +// #enddocregion alice + +////// Cathy /////////// +/** + * Show we can inject a parent by component type + */ +// #docregion cathy +@Component({ + selector: 'cathy', + template: ` +
+

Cathy

+ {{alex ? 'Found' : 'Did not find'}} Alex via the component class.
+
` +}) +export class CathyComponent { + constructor( @Optional() public alex: AlexComponent ) { } +} +// #enddocregion cathy + +///////// ParentFinder ////// +@Component({ + selector: 'parent-finder', + template: ` +

Parent Finder

+ + `, + directives: [ AlexComponent, AliceComponent ] +}) +export class ParentFinderComponent { } diff --git a/public/docs/_examples/cb-dependency-injection/ts/app/runners-up.ts b/public/docs/_examples/cb-dependency-injection/ts/app/runners-up.ts new file mode 100644 index 0000000000..a2d79df35e --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/app/runners-up.ts @@ -0,0 +1,25 @@ +// #docplaster +// #docregion +import {OpaqueToken} from 'angular2/core'; +import {Hero} from './hero'; +import {HeroService} from './hero.service'; + +// #docregion runners-up +export const RUNNERS_UP = new OpaqueToken('RunnersUp'); +// #docregion runners-up + +// #docregion factory-synopsis +export function runnersUpFactory(take: number) { + return (winner: Hero, heroService: HeroService): string => { + /* ... */ +// #enddocregion factory-synopsis + return heroService + .getAllHeroes() + .filter((hero) => hero.name !== winner.name) + .map(hero => hero.name) + .slice(0, Math.max(0, take)) + .join(', '); +// #docregion factory-synopsis + }; +}; +// #enddocregion factory-synopsis diff --git a/public/docs/_examples/cb-dependency-injection/ts/app/sorted-heroes.component.ts b/public/docs/_examples/cb-dependency-injection/ts/app/sorted-heroes.component.ts new file mode 100644 index 0000000000..2a45367044 --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/app/sorted-heroes.component.ts @@ -0,0 +1,51 @@ +// #docplaster +// #docregion +import {Component, OnInit} from 'angular2/core'; +import {Hero} from './hero'; +import {HeroService} from './hero.service'; + +/////// HeroesBaseComponent ///// +// #docregion heroes-base, injection +@Component({ + selector: 'unsorted-heroes', + template: `
{{hero.name}}
`, + providers: [HeroService] +}) +export class HeroesBaseComponent implements OnInit { + constructor(private _heroService: HeroService) { } +// #enddocregion injection + + heroes: Array; + + ngOnInit() { + this.heroes = this._heroService.getAllHeroes(); + this._afterGetHeroes(); + } + + // Post-process heroes in derived class override. + protected _afterGetHeroes() {} + +// #docregion injection +} +// #enddocregion heroes-base,injection + +/////// SortedHeroesComponent ///// +// #docregion sorted-heroes +@Component({ + selector: 'sorted-heroes', + template: `
{{hero.name}}
`, + providers: [HeroService] +}) +export class SortedHeroesComponent extends HeroesBaseComponent { + constructor(heroService: HeroService) { + super(heroService); + } + + protected _afterGetHeroes() { + this.heroes = this.heroes.sort((h1, h2) => { + return h1.name < h2.name ? -1 : + (h1.name > h2.name ? 1 : 0); + }); + } +} +// #enddocregion sorted-heroes diff --git a/public/docs/_examples/cb-dependency-injection/ts/app/user-context.service.ts b/public/docs/_examples/cb-dependency-injection/ts/app/user-context.service.ts new file mode 100644 index 0000000000..b241675d31 --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/app/user-context.service.ts @@ -0,0 +1,32 @@ +// #docplaster +// #docregion +import {Injectable} from 'angular2/core'; +import {LoggerService} from './logger.service'; +import {UserService} from './user.service'; + +// #docregion injectables, injectable +@Injectable() +export class UserContextService { +// #enddocregion injectables, injectable + name:string; + role:string; + loggedInSince:Date; + + // #docregion ctor, injectables + constructor(private _userService:UserService, private _loggerService:LoggerService){ + // #enddocregion ctor, injectables + this.loggedInSince = new Date(); + // #docregion ctor, injectables + } + // #enddocregion ctor, injectables + + loadUser(userId:number){ + let user = this._userService.getUserById(userId); + this.name = user.name; + this.role = user.role; + + this._loggerService.logDebug('loaded User'); + } +// #docregion injectables, injectable +} +// #enddocregion injectables, injectable diff --git a/public/docs/_examples/cb-dependency-injection/ts/app/user.service.ts b/public/docs/_examples/cb-dependency-injection/ts/app/user.service.ts new file mode 100644 index 0000000000..f2d44d7a26 --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/app/user.service.ts @@ -0,0 +1,10 @@ +// #docregion +import {Injectable} from 'angular2/core'; + +@Injectable() +export class UserService { + + getUserById(userId:number):any{ + return {name:'Bombasto',role:'Admin'}; + } +} \ No newline at end of file diff --git a/public/docs/_examples/cb-dependency-injection/ts/example-config.json b/public/docs/_examples/cb-dependency-injection/ts/example-config.json new file mode 100644 index 0000000000..e69de29bb2 diff --git a/public/docs/_examples/cb-dependency-injection/ts/index.html b/public/docs/_examples/cb-dependency-injection/ts/index.html new file mode 100644 index 0000000000..66db40eb30 --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/index.html @@ -0,0 +1,44 @@ + + + + + Dependency Injection + + + + + + + + + + + + + + + + + + + + + + + + + Loading app... + + + diff --git a/public/docs/_examples/cb-dependency-injection/ts/plnkr.json b/public/docs/_examples/cb-dependency-injection/ts/plnkr.json new file mode 100644 index 0000000000..d20b01cf1d --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/plnkr.json @@ -0,0 +1,9 @@ +{ + "description": "Dependency Injection", + "files":[ + "!**/*.d.ts", + "!**/*.js", + "!**/*.[1].*" + ], + "tags":["cookbook"] +} \ No newline at end of file diff --git a/public/docs/_examples/cb-dependency-injection/ts/sample.css b/public/docs/_examples/cb-dependency-injection/ts/sample.css new file mode 100644 index 0000000000..a8b59efd05 --- /dev/null +++ b/public/docs/_examples/cb-dependency-injection/ts/sample.css @@ -0,0 +1,26 @@ +.di-component{ + padding: 10px; + width:300px; + margin-bottom: 10px; +} +div[myHighlight] { + padding: 2px 8px; +} + +/* Parent Finder */ +.a, .b, .c { + margin: 6px 2px 6px; + padding: 4px 6px; +} +.a { + border: solid 2px black; +} +.b { + background: lightblue; + border: solid 1px darkblue; + display: flex; +} +.c { + background: pink; + border: solid 1px red; +} \ No newline at end of file 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/_examples/component-styles/e2e-spec.js b/public/docs/_examples/component-styles/e2e-spec.js new file mode 100644 index 0000000000..e667260f99 --- /dev/null +++ b/public/docs/_examples/component-styles/e2e-spec.js @@ -0,0 +1,69 @@ +describe('Component Style Tests', function () { + + beforeAll(function () { + browser.get(''); + }); + + it('scopes component styles to component view', function() { + var componentH1 = element(by.css('hero-app > h1')); + var externalH1 = element(by.css('body > h1')); + + expect(componentH1.getCssValue('fontWeight')).toEqual('normal'); + expect(externalH1.getCssValue('fontWeight')).not.toEqual('normal'); + }); + + + it('allows styling :host element', function() { + var host = element(by.css('hero-details')); + + expect(host.getCssValue('borderWidth')).toEqual('1px'); + }); + + it('supports :host() in function form', function() { + var host = element(by.css('hero-details')); + + host.element(by.buttonText('Activate')).click(); + expect(host.getCssValue('borderWidth')).toEqual('3px'); + }); + + it('allows conditional :host-context() styling', function() { + var h2 = element(by.css('hero-details h2')); + + expect(h2.getCssValue('backgroundColor')).toEqual('rgba(238, 238, 255, 1)'); // #eeeeff + }); + + it('styles both view and content children with /deep/', function() { + var viewH3 = element(by.css('hero-team h3')); + var contentH3 = element(by.css('hero-controls h3')); + + expect(viewH3.getCssValue('fontStyle')).toEqual('italic'); + expect(contentH3.getCssValue('fontStyle')).toEqual('italic'); + }); + + it('includes styles loaded with CSS @import', function() { + var host = element(by.css('hero-details')); + + expect(host.getCssValue('padding')).toEqual('10px'); + }); + + it('processes template inline styles', function() { + var button = element(by.css('hero-controls button')); + var externalButton = element(by.css('body > button')); + expect(button.getCssValue('backgroundColor')).toEqual('rgba(255, 255, 255, 1)'); // #ffffff + expect(externalButton.getCssValue('backgroundColor')).not.toEqual('rgba(255, 255, 255, 1)'); + }); + + it('processes template s', function() { + var li = element(by.css('hero-team li:first-child')); + var externalLi = element(by.css('body > ul li')); + + expect(li.getCssValue('listStyleType')).toEqual('square'); + expect(externalLi.getCssValue('listStyleType')).not.toEqual('square'); + }); + + it('supports relative loading with moduleId', function() { + var host = element(by.css('quest-summary')); + expect(host.getCssValue('color')).toEqual('rgba(255, 255, 255, 1)'); // #ffffff + }); + +}); diff --git a/public/docs/_examples/component-styles/ts/.gitignore b/public/docs/_examples/component-styles/ts/.gitignore new file mode 100644 index 0000000000..2cb7d2a2e9 --- /dev/null +++ b/public/docs/_examples/component-styles/ts/.gitignore @@ -0,0 +1 @@ +**/*.js diff --git a/public/docs/_examples/component-styles/ts/app/hero-app-main.component.ts b/public/docs/_examples/component-styles/ts/app/hero-app-main.component.ts new file mode 100644 index 0000000000..b127a95b5e --- /dev/null +++ b/public/docs/_examples/component-styles/ts/app/hero-app-main.component.ts @@ -0,0 +1,19 @@ +import {Component, Input} from 'angular2/core'; +import {Hero} from './hero'; +import {HeroDetailsComponent} from './hero-details.component'; +import {HeroControlsComponent} from './hero-controls.component'; +import {QuestSummaryComponent} from './quest-summary.component'; + +@Component({ + selector: 'hero-app-main', + template: ` + + + + + `, + directives: [HeroDetailsComponent, HeroControlsComponent, QuestSummaryComponent] +}) +export class HeroAppMainComponent { + @Input() hero: Hero; +} diff --git a/public/docs/_examples/component-styles/ts/app/hero-app.component.ts b/public/docs/_examples/component-styles/ts/app/hero-app.component.ts new file mode 100644 index 0000000000..8eb5c9116c --- /dev/null +++ b/public/docs/_examples/component-styles/ts/app/hero-app.component.ts @@ -0,0 +1,25 @@ +import {Component, HostBinding} from 'angular2/core'; +import {Hero} from './hero'; +import {HeroAppMainComponent} from './hero-app-main.component'; + +// #docregion +@Component({ + selector: 'hero-app', + template: ` +

Tour of Heroes

+ `, + styles: ['h1 { font-weight: normal; }'], + directives: [HeroAppMainComponent] +}) +// #enddocregion +export class HeroAppComponent { + hero = new Hero( + 'Human Torch', + ['Mister Fantastic', 'Invisible Woman', 'Thing'] + ) + + @HostBinding('class') get themeClass() { + return 'theme-light'; + } + +} diff --git a/public/docs/_examples/component-styles/ts/app/hero-controls.component.ts b/public/docs/_examples/component-styles/ts/app/hero-controls.component.ts new file mode 100644 index 0000000000..fb674d0a63 --- /dev/null +++ b/public/docs/_examples/component-styles/ts/app/hero-controls.component.ts @@ -0,0 +1,26 @@ +import {Component, Input} from 'angular2/core'; +import {Hero} from './hero'; + +// #docregion inlinestyles +@Component({ + selector: 'hero-controls', + template: ` + +

Controls

+ + ` +}) +// #enddocregion inlinestyles +export class HeroControlsComponent { + + @Input() hero: Hero; + + activate() { + this.hero.active = true; + } +} diff --git a/public/docs/_examples/component-styles/ts/app/hero-details-box.css b/public/docs/_examples/component-styles/ts/app/hero-details-box.css new file mode 100644 index 0000000000..f240073005 --- /dev/null +++ b/public/docs/_examples/component-styles/ts/app/hero-details-box.css @@ -0,0 +1,3 @@ +:host { + padding: 10px; +} diff --git a/public/docs/_examples/component-styles/ts/app/hero-details.component.css b/public/docs/_examples/component-styles/ts/app/hero-details.component.css new file mode 100644 index 0000000000..fd938ca55c --- /dev/null +++ b/public/docs/_examples/component-styles/ts/app/hero-details.component.css @@ -0,0 +1,28 @@ +/* #docregion import */ +@import 'hero-details-box.css'; +/* #enddocregion import */ + +/* #docregion host */ +:host { + display: block; + border: 1px solid black; +} +/* #enddocregion host */ + +/* #docregion hostfunction */ +:host(.active) { + border-width: 3px; +} +/* #enddocregion hostfunction */ + +/* #docregion hostcontext */ +:host-context(.theme-light) h2 { + background-color: #eef; +} +/* #enddocregion hostcontext */ + +/* #docregion deep */ +:host /deep/ h3 { + font-style: italic; +} +/* #enddocregion deep */ diff --git a/public/docs/_examples/component-styles/ts/app/hero-details.component.ts b/public/docs/_examples/component-styles/ts/app/hero-details.component.ts new file mode 100644 index 0000000000..344063a543 --- /dev/null +++ b/public/docs/_examples/component-styles/ts/app/hero-details.component.ts @@ -0,0 +1,20 @@ +import {Component, Input} from 'angular2/core'; +import {Hero} from './hero'; +import {HeroTeamComponent} from './hero-team.component'; + +// #docregion styleurls +@Component({ + selector: 'hero-details', + template: ` +

{{hero.name}}

+ + + `, + styleUrls: ['app/hero-details.component.css'], + directives: [HeroTeamComponent] +}) +export class HeroDetailsComponent { +// #enddocregion styleurls + + @Input() hero:Hero; +} diff --git a/public/docs/_examples/component-styles/ts/app/hero-team.component.css b/public/docs/_examples/component-styles/ts/app/hero-team.component.css new file mode 100644 index 0000000000..b87679886b --- /dev/null +++ b/public/docs/_examples/component-styles/ts/app/hero-team.component.css @@ -0,0 +1,3 @@ +li { + list-style-type: square; +} diff --git a/public/docs/_examples/component-styles/ts/app/hero-team.component.ts b/public/docs/_examples/component-styles/ts/app/hero-team.component.ts new file mode 100644 index 0000000000..78885ff1ea --- /dev/null +++ b/public/docs/_examples/component-styles/ts/app/hero-team.component.ts @@ -0,0 +1,19 @@ +import {Component, Input} from 'angular2/core'; +import {Hero} from './hero'; + +// #docregion stylelink +@Component({ + selector: 'hero-team', + template: ` + +

Team

+
    +
  • + {{member}} +
  • +
` +}) +// #enddocregion stylelink +export class HeroTeamComponent { + @Input() hero: Hero; +} diff --git a/public/docs/_examples/component-styles/ts/app/hero.ts b/public/docs/_examples/component-styles/ts/app/hero.ts new file mode 100644 index 0000000000..8b58c8a8f8 --- /dev/null +++ b/public/docs/_examples/component-styles/ts/app/hero.ts @@ -0,0 +1,7 @@ +export class Hero { + active:boolean; + + constructor(public name:string, + public team:string[]) { + } +} diff --git a/public/docs/_examples/component-styles/ts/app/main.ts b/public/docs/_examples/component-styles/ts/app/main.ts new file mode 100644 index 0000000000..a9194f16f3 --- /dev/null +++ b/public/docs/_examples/component-styles/ts/app/main.ts @@ -0,0 +1,4 @@ +import {bootstrap} from 'angular2/platform/browser'; +import {HeroAppComponent} from './hero-app.component'; + +bootstrap(HeroAppComponent); diff --git a/public/docs/_examples/component-styles/ts/app/quest-summary.component.css b/public/docs/_examples/component-styles/ts/app/quest-summary.component.css new file mode 100644 index 0000000000..207fa981dd --- /dev/null +++ b/public/docs/_examples/component-styles/ts/app/quest-summary.component.css @@ -0,0 +1,5 @@ +:host { + display: block; + background-color: green; + color: white; +} diff --git a/public/docs/_examples/component-styles/ts/app/quest-summary.component.html b/public/docs/_examples/component-styles/ts/app/quest-summary.component.html new file mode 100644 index 0000000000..abf63c2542 --- /dev/null +++ b/public/docs/_examples/component-styles/ts/app/quest-summary.component.html @@ -0,0 +1 @@ +No quests in progress diff --git a/public/docs/_examples/component-styles/ts/app/quest-summary.component.ts b/public/docs/_examples/component-styles/ts/app/quest-summary.component.ts new file mode 100644 index 0000000000..daea1a26b9 --- /dev/null +++ b/public/docs/_examples/component-styles/ts/app/quest-summary.component.ts @@ -0,0 +1,32 @@ +// #docplaster +import {Component, ViewEncapsulation} from 'angular2/core'; + +// #docregion +// Let TypeScript know about the special SystemJS __moduleName variable +declare var __moduleName: string; +// #enddocregion +// moduleName is not set in some module loaders; set it explicitly +if (!__moduleName) { + __moduleName = `http://${location.host}/${location.pathname}/app/`; +} +console.log(`The __moduleName is ${__moduleName} `); +// #docregion + +@Component({ + moduleId: __moduleName, + selector: 'quest-summary', + // #docregion urls + templateUrl: 'quest-summary.component.html', + styleUrls: ['quest-summary.component.css'] + // #enddocregion urls +// #enddocregion +/* + // #docregion encapsulation.native + // warning: few browsers support shadow DOM encapsulation at this time + encapsulation: ViewEncapsulation.Native + // #enddocregion encapsulation.native +*/ +// #docregion +}) +export class QuestSummaryComponent { } +// #enddocregion diff --git a/public/docs/_examples/component-styles/ts/example-config.json b/public/docs/_examples/component-styles/ts/example-config.json new file mode 100644 index 0000000000..e69de29bb2 diff --git a/public/docs/_examples/component-styles/ts/index.html b/public/docs/_examples/component-styles/ts/index.html new file mode 100644 index 0000000000..58098522ff --- /dev/null +++ b/public/docs/_examples/component-styles/ts/index.html @@ -0,0 +1,40 @@ + + + + Component Styles + + + + + + + + + + + + + + + + +

External H1 Title for E2E test

+ + +
    +
  • External list for E2E test
  • +
+ + + diff --git a/public/docs/_examples/component-styles/ts/plnkr.json b/public/docs/_examples/component-styles/ts/plnkr.json new file mode 100644 index 0000000000..fb313556fc --- /dev/null +++ b/public/docs/_examples/component-styles/ts/plnkr.json @@ -0,0 +1,9 @@ +{ + "description": "Component Styles", + "files": [ + "!**/*.d.ts", + "!**/*.js", + "!**/*.native.*" + ], + "tags": ["CSS"] +} diff --git a/public/docs/_examples/dependency-injection/dart/.analysis_options b/public/docs/_examples/dependency-injection/dart/.analysis_options new file mode 100644 index 0000000000..d8c582e96f --- /dev/null +++ b/public/docs/_examples/dependency-injection/dart/.analysis_options @@ -0,0 +1,16 @@ +# Supported lint rules and documentation: http://dart-lang.github.io/linter/lints/ +linter: + rules: + - always_declare_return_types + - camel_case_types + - empty_constructor_bodies + - annotate_overrides + - avoid_init_to_null + - constant_identifier_names + - one_member_abstracts + - slash_for_doc_comments + - sort_constructors_first + - unnecessary_brace_in_string_interp + +analyzer: + # strong-mode: true diff --git a/public/docs/_examples/dependency-injection/dart/lib/app_component.dart b/public/docs/_examples/dependency-injection/dart/lib/app_component.dart index 4e01554a42..1a9e4f075b 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/app_component.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/app_component.dart @@ -1,15 +1,14 @@ // #docplaster - // #docregion - // #docregion imports import 'package:angular2/core.dart'; + +import 'app_config.dart'; import 'car/car_component.dart'; import 'heroes/heroes_component.dart'; -import 'app_config.dart'; import 'logger_service.dart'; import 'user_service.dart'; - +//PENDING: check whether we intend to hide injector_component.dart & providers_component.dart; if so, change docregion name? // #enddocregion imports import 'injector_component.dart'; import 'providers_component.dart'; @@ -17,33 +16,39 @@ import 'providers_component.dart'; @Component( selector: 'my-app', template: ''' -

{{title}}

- - - -

User

-

- {{userInfo}} - -

- - - ''', - directives: const [CarComponent, HeroesComponent, InjectorComponent, ProvidersComponent], +

{{title}}

+ + + +

User

+

+ {{userInfo}} + +

+ + ''', + directives: const [ + CarComponent, + HeroesComponent, + InjectorComponent, + ProvidersComponent + ], // #docregion providers - providers: const [Logger, UserService, const Provider(Config, useValue: CONFIG)] + providers: const [ + Logger, + UserService, + const Provider(AppConfig, useValue: config1)] // #enddocregion providers - ) +) class AppComponent { - UserService _userService; - String title; + final UserService _userService; + final String title; //#docregion ctor - AppComponent(Config config, this._userService) { - title = config.title; - } - + AppComponent(AppConfig config, this._userService) + : title = config.title; // #enddocregion ctor + bool get isAuthorized { return user.isAuthorized; } @@ -56,8 +61,7 @@ class AppComponent { return _userService.user; } - String get userInfo { - return 'Current user, ${user.name}, is ${isAuthorized ? "" : "not"} authorized. '; - } + String get userInfo => 'Current user, ${user.name}, is' + '${isAuthorized ? "" : " not"} authorized. '; } // #enddocregion diff --git a/public/docs/_examples/dependency-injection/dart/lib/app_component_1.dart b/public/docs/_examples/dependency-injection/dart/lib/app_component_1.dart index 7c3b7b9808..2466b4894b 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/app_component_1.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/app_component_1.dart @@ -2,19 +2,19 @@ // #docregion import 'package:angular2/core.dart'; + import 'car/car_component.dart'; import 'heroes/heroes_component_1.dart'; @Component( selector: 'my-app', template: ''' -

{{title}}

- - - ''', +

{{title}}

+ + ''', directives: const [CarComponent, HeroesComponent]) class AppComponent { - var title = 'Dependency Injection'; + final String title = 'Dependency Injection'; } // #enddocregion diff --git a/public/docs/_examples/dependency-injection/dart/lib/app_component_2.dart b/public/docs/_examples/dependency-injection/dart/lib/app_component_2.dart index 7bf4249ee2..4463b7c59c 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/app_component_2.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/app_component_2.dart @@ -2,34 +2,32 @@ // #docregion imports import 'package:angular2/core.dart'; + +import 'app_config.dart'; import 'car/car_component.dart'; import 'heroes/heroes_component_1.dart'; -import 'app_config.dart'; import 'logger_service.dart'; - // #enddocregion imports + @Component( selector: 'my-app', template: ''' -

{{title}}

- - - ''', +

{{title}}

+ + ''', directives: const [ CarComponent, HeroesComponent ], providers: const [ Logger, - // #docregion provider-config - const Provider('app.config', useValue: CONFIG) + const Provider(AppConfig, useValue: config1) ]) class AppComponent { - String title; + final String title; // #docregion ctor - AppComponent(@Inject('app.config') Config config) { - title = config.title; - } + AppComponent(AppConfig config) + : title = config.title; + // #enddocregion } -// #enddocregion diff --git a/public/docs/_examples/dependency-injection/dart/lib/app_config.dart b/public/docs/_examples/dependency-injection/dart/lib/app_config.dart index 8fc877f188..7785eff1b4 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/app_config.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/app_config.dart @@ -1,29 +1,17 @@ -//#docregion - +// #docregion // #docregion token import 'package:angular2/core.dart'; -const APP_CONFIG = const OpaqueToken('app.config'); -// #enddocregion token - -//#docregion config -abstract class Config { - final String apiEndpoint; +//#docregion const-class +@Injectable() +class AppConfig { + final apiEndpoint; final String title; - const Config({this.apiEndpoint, this.title}); + const AppConfig(this.apiEndpoint, this.title); } +//#enddocregion const-class -class ConfigImpl implements Config { - final String apiEndpoint; - final String title; - - const ConfigImpl({this.apiEndpoint, this.title}); -} - -const CONFIG = const ConfigImpl(apiEndpoint: 'api.heroes.com', title: 'Dependency Injection'); -//#enddocregion config - -//#docregion config-hash -const CONFIG_HASH = const {'apiEndpoint': 'api.heroes.com', 'title': 'Dependency Injection'}; -//#enddocregion config-hash +//#docregion const-object +const config1 = const AppConfig('api.heroes.com', 'Dependency Injection'); +//#enddocregion const-object diff --git a/public/docs/_examples/dependency-injection/dart/lib/car/car.dart b/public/docs/_examples/dependency-injection/dart/lib/car/car.dart index 4c8d1025e7..cacd0d9b69 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/car/car.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/car/car.dart @@ -1,13 +1,14 @@ // #docregion - import 'package:angular2/core.dart'; +@Injectable() // #docregion engine class Engine { - int cylinders = 4; + final int cylinders = 4; } // #enddocregion engine +@Injectable() // #docregion tires class Tires { String make = 'Flintstone'; @@ -18,8 +19,8 @@ class Tires { @Injectable() class Car { //#docregion car-ctor - Engine engine; - Tires tires; + final Engine engine; + final Tires tires; String description = 'DI'; Car(this.engine, this.tires); @@ -27,6 +28,7 @@ class Car { // #enddocregion car-ctor // Method using the engine and tires - String drive() => '$description car with ${engine.cylinders} cylinders and ${tires.make} tires.'; + String drive() => '$description car with ${engine.cylinders} cylinders' + ' and ${tires.make} tires.'; } // #enddocregion car diff --git a/public/docs/_examples/dependency-injection/dart/lib/car/car_component.dart b/public/docs/_examples/dependency-injection/dart/lib/car/car_component.dart index e8e3ccc0e0..b7e663b019 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/car/car_component.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/car/car_component.dart @@ -1,29 +1,29 @@ // #docregion - import 'package:angular2/core.dart'; + import 'car.dart'; -import 'car_no_di.dart' as carNoDi; -import 'car_factory.dart'; import 'car_creations.dart' as carCreations; +import 'car_factory.dart'; import 'car_injector.dart'; +import 'car_no_di.dart' as carNoDi; @Component( selector: 'my-car', template: ''' -

Cars

-
{{car.drive()}}
-
{{noDiCar.drive()}}
-
{{injectorCar.drive()}}
-
{{factoryCar.drive()}}
-
{{simpleCar.drive()}}
-
{{superCar.drive()}}
-
{{testCar.drive()}}
- ''', +

Cars

+
{{car.drive()}}
+
{{noDiCar.drive()}}
+
{{injectorCar.drive()}}
+
{{factoryCar.drive()}}
+
{{simpleCar.drive()}}
+
{{superCar.drive()}}
+
{{testCar.drive()}}
''', providers: const [Car, Engine, Tires]) class CarComponent { - Car car; + final Car car; + + CarComponent(this.car); - CarComponent(this.car) {} Car factoryCar = (new CarFactory()).createCar(); Car injectorCar = useInjector(); carNoDi.Car noDiCar = new carNoDi.Car(); diff --git a/public/docs/_examples/dependency-injection/dart/lib/car/car_creations.dart b/public/docs/_examples/dependency-injection/dart/lib/car/car_creations.dart index 33dfa05828..d0e6be3c1c 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/car/car_creations.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/car/car_creations.dart @@ -1,12 +1,10 @@ -// Examples with car and engine variations - // #docplaster +// Examples with car and engine variations import 'car.dart'; ///////// example 1 //////////// Car simpleCar() { //#docregion car-ctor-instantiation - // Simple car with 4 cylinders and Flintstone tires. var car = new Car(new Engine(), new Tires()); //#enddocregion car-ctor-instantiation @@ -17,19 +15,18 @@ Car simpleCar() { //#docregion car-ctor-instantiation-with-param class Engine2 implements Engine { - int cylinders; + final int cylinders; Engine2(this.cylinders); } - //#enddocregion car-ctor-instantiation-with-param -Car superCar() { - //#docregion car-ctor-instantiation-with-param - // Super car with 12 cylinders and Flintstone tires. - var bigCylinders = 12; - var car = new Car(new Engine2(bigCylinders), new Tires()); - //#enddocregion car-ctor-instantiation-with-param +Car superCar() { +//#docregion car-ctor-instantiation-with-param +// Super car with 12 cylinders and Flintstone tires. +var bigCylinders = 12; +var car = new Car(new Engine2(bigCylinders), new Tires()); +//#enddocregion car-ctor-instantiation-with-param car.description = 'Super'; return car; } @@ -37,7 +34,7 @@ Car superCar() { //#docregion car-ctor-instantiation-with-mocks class MockEngine extends Engine { - int cylinders = 8; + final int cylinders = 8; } class MockTires extends Tires { @@ -46,11 +43,10 @@ class MockTires extends Tires { //#enddocregion car-ctor-instantiation-with-mocks Car testCar() { - //#docregion car-ctor-instantiation-with-mocks - - // Test car with 8 cylinders and YokoGoodStone tires. - var car = new Car(new MockEngine(), new MockTires()); - //#enddocregion car-ctor-instantiation-with-mocks +//#docregion car-ctor-instantiation-with-mocks +// Test car with 8 cylinders and YokoGoodStone tires. +var car = new Car(new MockEngine(), new MockTires()); +//#enddocregion car-ctor-instantiation-with-mocks car.description = 'Test'; return car; } diff --git a/public/docs/_examples/dependency-injection/dart/lib/car/car_factory.dart b/public/docs/_examples/dependency-injection/dart/lib/car/car_factory.dart index 76b8a4cc63..7610e28b14 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/car/car_factory.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/car/car_factory.dart @@ -1,15 +1,13 @@ // #docregion - import 'car.dart'; +// BAD pattern! class CarFactory { Car createCar() { - var car = new Car(createEngine(), createTires()); - car.description = 'Factory'; - return car; + return new Car(createEngine(), createTires()) + ..description = 'Factory'; } Engine createEngine() => new Engine(); - Tires createTires() => new Tires(); } diff --git a/public/docs/_examples/dependency-injection/dart/lib/car/car_injector.dart b/public/docs/_examples/dependency-injection/dart/lib/car/car_injector.dart index 1dbadd9fab..d3da37a9e7 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/car/car_injector.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/car/car_injector.dart @@ -1,9 +1,9 @@ // #docplaster - //#docregion import 'package:angular2/core.dart'; -import 'car.dart'; + import '../logger_service.dart'; +import 'car.dart'; //#docregion injector Car useInjector() { @@ -24,8 +24,8 @@ Car useInjector() { //#docregion injector-call var car = injector.get(Car); //#enddocregion injector-call - //#enddocregion injector-create-and-call + car.description = 'Injector'; var logger = injector.get(Logger); logger.log('Injector car.drive() said: ' + car.drive()); diff --git a/public/docs/_examples/dependency-injection/dart/lib/car/car_no_di.dart b/public/docs/_examples/dependency-injection/dart/lib/car/car_no_di.dart index 32972c3dc1..86a4177b2d 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/car/car_no_di.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/car/car_no_di.dart @@ -13,10 +13,10 @@ class Car { engine = new Engine(); tires = new Tires(); } - //#enddocregion car-ctor // Method using the engine and tires - drive() => '$description car with ${engine.cylinders} cylinders and ${tires.make} tires.'; + String drive() => '$description car with ' + '${engine.cylinders} cylinders and ${tires.make} tires.'; } //#enddocregion car diff --git a/public/docs/_examples/dependency-injection/dart/lib/heroes/hero.dart b/public/docs/_examples/dependency-injection/dart/lib/heroes/hero.dart index ea10276b7c..2a76844f9c 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/heroes/hero.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/heroes/hero.dart @@ -1,5 +1,4 @@ // #docregion - class Hero { num id; String name; diff --git a/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_list_component.dart b/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_list_component.dart index c4eeb14f1b..0c79b2f600 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_list_component.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_list_component.dart @@ -1,19 +1,18 @@ // #docregion - import 'package:angular2/core.dart'; + import 'hero.dart'; import 'hero_service.dart'; @Component( selector: 'hero-list', template: ''' -
- {{hero.id}} - {{hero.name}} - ({{hero.isSecret ? \'secret\' : \'public\'}}) -
- ''') +
+ {{hero.id}} - {{hero.name}} + ({{hero.isSecret ? 'secret' : 'public'}}) +
''') class HeroListComponent { - List heroes; + final List heroes; //#docregion ctor-signature HeroListComponent(HeroService heroService) : heroes = heroService.getHeroes(); diff --git a/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_list_component_1.dart b/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_list_component_1.dart index 3aeef5aefb..366cf570b0 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_list_component_1.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_list_component_1.dart @@ -1,16 +1,15 @@ // #docregion - import 'package:angular2/core.dart'; + import 'hero.dart'; import 'mock_heroes.dart'; @Component( selector: 'hero-list', template: ''' -
- {{hero.id}} - {{hero.name}} -
- ''') +
+ {{hero.id}} - {{hero.name}} +
''') class HeroListComponent { - List heroes = HEROES; + final List heroes = HEROES; } diff --git a/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_list_component_2.dart b/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_list_component_2.dart index 2b76419505..637ca74b00 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_list_component_2.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_list_component_2.dart @@ -1,20 +1,20 @@ // #docregion - import 'package:angular2/core.dart'; + import 'hero.dart'; import 'hero_service.dart'; @Component( selector: 'hero-list', template: ''' -
- {{hero.id}} - {{hero.name}} -
- ''') +
+ {{hero.id}} - {{hero.name}} +
''') class HeroListComponent { - List heroes; + final List heroes; //#docregion ctor - HeroListComponent(HeroService heroService) : heroes = heroService.getHeroes(); + HeroListComponent(HeroService heroService) + : heroes = heroService.getHeroes(); //#enddocregion ctor } diff --git a/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_service.dart b/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_service.dart index 2dda48cb70..59074e3cd4 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_service.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_service.dart @@ -1,22 +1,24 @@ // #docregion - import 'package:angular2/core.dart'; + +import '../logger_service.dart'; import 'hero.dart'; import 'mock_heroes.dart'; -import '../logger_service.dart'; @Injectable() class HeroService { // #docregion internals - Logger _logger; - bool _isAuthorized; + final Logger _logger; + final bool _isAuthorized; HeroService(this._logger, this._isAuthorized); List getHeroes() { var auth = _isAuthorized ? 'authorized' : 'unauthorized'; - _logger.log('Getting heroes for ${auth} user.'); - return HEROES.where((hero) => _isAuthorized || !hero.isSecret).toList(); + _logger.log('Getting heroes for $auth user.'); + return HEROES + .where((hero) => _isAuthorized || !hero.isSecret) + .toList(); } // #enddocregion internals } diff --git a/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_service_1.dart b/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_service_1.dart index 7ee6a642b4..f400d86fc4 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_service_1.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_service_1.dart @@ -1,5 +1,4 @@ // #docregion - import 'hero.dart'; import 'mock_heroes.dart'; diff --git a/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_service_2.dart b/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_service_2.dart index 25146a76f9..badd8f548e 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_service_2.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_service_2.dart @@ -1,13 +1,13 @@ // #docregion - import 'package:angular2/core.dart'; + +import '../logger_service.dart'; import 'hero.dart'; import 'mock_heroes.dart'; -import '../logger_service.dart'; @Injectable() class HeroService { - Logger _logger; + final Logger _logger; //#docregion ctor HeroService(this._logger); diff --git a/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_service_provider.dart b/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_service_provider.dart index b783f0edc5..7e457e2db9 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_service_provider.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/heroes/hero_service_provider.dart @@ -1,16 +1,18 @@ // #docregion - import 'package:angular2/core.dart'; -import 'hero_service.dart'; + import '../logger_service.dart'; import '../user_service.dart'; +import 'hero_service.dart'; // #docregion factory +@Injectable() heroServiceFactory(Logger logger, UserService userService) => new HeroService(logger, userService.user.isAuthorized); // #enddocregion factory // #docregion provider -const heroServiceProvider = - const Provider(HeroService, useFactory: heroServiceFactory, deps: const [Logger, UserService]); +const heroServiceProvider = const Provider(HeroService, + useFactory: heroServiceFactory, + deps: const [Logger, UserService]); // #enddocregion provider diff --git a/public/docs/_examples/dependency-injection/dart/lib/heroes/heroes_component.dart b/public/docs/_examples/dependency-injection/dart/lib/heroes/heroes_component.dart index 45e310cd30..d90871de73 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/heroes/heroes_component.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/heroes/heroes_component.dart @@ -1,15 +1,14 @@ // #docregion - import 'package:angular2/core.dart'; + import 'hero_list_component.dart'; import 'hero_service_provider.dart'; @Component( selector: 'my-heroes', template: ''' -

Heroes

- - ''', +

Heroes

+ ''', providers: const [heroServiceProvider], directives: const [HeroListComponent]) class HeroesComponent {} diff --git a/public/docs/_examples/dependency-injection/dart/lib/heroes/heroes_component_1.dart b/public/docs/_examples/dependency-injection/dart/lib/heroes/heroes_component_1.dart index 80d7ad8f2e..19cde705ce 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/heroes/heroes_component_1.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/heroes/heroes_component_1.dart @@ -1,20 +1,18 @@ // #docplaster - // #docregion // #docregion v1 import 'package:angular2/core.dart'; -import 'hero_list_component.dart'; +import 'hero_list_component.dart'; // #enddocregion v1 import 'hero_service.dart'; - // #docregion v1 + @Component( selector: 'my-heroes', template: ''' -

Heroes

- - ''', +

Heroes

+ ''', // #enddocregion v1 // #docregion providers providers: const [HeroService], diff --git a/public/docs/_examples/dependency-injection/dart/lib/heroes/mock_heroes.dart b/public/docs/_examples/dependency-injection/dart/lib/heroes/mock_heroes.dart index 9f49bf208c..2501f92081 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/heroes/mock_heroes.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/heroes/mock_heroes.dart @@ -1,5 +1,4 @@ // #docregion - import 'hero.dart'; List HEROES = [ diff --git a/public/docs/_examples/dependency-injection/dart/lib/injector_component.dart b/public/docs/_examples/dependency-injection/dart/lib/injector_component.dart index 24e1598f13..ecc85f9c39 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/injector_component.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/injector_component.dart @@ -2,21 +2,21 @@ //#docregion import 'package:angular2/core.dart'; + import 'car/car.dart'; +import 'heroes/hero.dart'; import 'heroes/hero_service.dart'; import 'heroes/hero_service_provider.dart'; import 'logger_service.dart'; -import 'package:dependency_injection/heroes/hero.dart'; //#docregion injector @Component( selector: 'my-injectors', template: ''' -

Other Injections

-
{{car.drive()}}
-
{{hero.name}}
-
{{rodent}}
- ''', +

Other Injections

+
{{car.drive()}}
+
{{hero.name}}
+
{{rodent}}
''', providers: const [ Car, Engine, @@ -25,20 +25,9 @@ import 'package:dependency_injection/heroes/hero.dart'; Logger ]) class InjectorComponent { - Injector _injector; - - InjectorComponent(this._injector) { - car = _injector.get(Car); - heroService = _injector.get(HeroService); - hero = heroService.getHeroes()[0]; - } - + final Injector _injector; Car car; - - //#docregion get-hero-service HeroService heroService; - - //#enddocregion get-hero-service Hero hero; String get rodent { @@ -48,6 +37,14 @@ class InjectorComponent { } return "R.O.U.S.'s? I don't think they exist!"; } + + InjectorComponent(this._injector) { + car = _injector.get(Car); + //#docregion get-hero-service + heroService = _injector.get(HeroService); + //#enddocregion get-hero-service + hero = heroService.getHeroes()[0]; + } } //#enddocregion injector diff --git a/public/docs/_examples/dependency-injection/dart/lib/logger_service.dart b/public/docs/_examples/dependency-injection/dart/lib/logger_service.dart index 452daefd22..38b4450f25 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/logger_service.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/logger_service.dart @@ -1,5 +1,4 @@ // #docregion - import 'package:angular2/core.dart'; @Injectable() diff --git a/public/docs/_examples/dependency-injection/dart/lib/providers_component.dart b/public/docs/_examples/dependency-injection/dart/lib/providers_component.dart index 83d461deb2..34a1c82f3e 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/providers_component.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/providers_component.dart @@ -2,22 +2,19 @@ //#docplaster import 'package:angular2/core.dart'; + import 'app_config.dart'; import 'heroes/hero_service_provider.dart'; import 'heroes/hero_service.dart'; import 'logger_service.dart'; import 'user_service.dart'; -// #docregion import-optional -import 'package:angular2/core.dart' show Optional; -// #enddocregion import-optional - -const template = '{{log}}'; - -////////////////////////////////////////// -@Component(selector: 'provider-1', template: '{{log}}', providers: +@Component( + selector: 'provider-1', + template: '{{log}}', + providers: //#docregion providers-1 -const [Logger] + const [Logger] //#enddocregion providers-1 ) class ProviderComponent1 { @@ -25,14 +22,16 @@ class ProviderComponent1 { ProviderComponent1(Logger logger) { logger.log('Hello from logger provided with Logger class'); - log = logger.logs[0]; + log = logger.logs.last; } } -////////////////////////////////////////// -@Component(selector: 'provider-2', template: '{{log}}', providers: +@Component( + selector: 'provider-2', + template: '{{log}}', + providers: //#docregion providers-2 -const [const Provider(Logger, useClass: Logger)] + const [const Provider(Logger, useClass: Logger)] //#enddocregion providers-2 ) class ProviderComponent2 { @@ -40,36 +39,32 @@ class ProviderComponent2 { ProviderComponent2(Logger logger) { logger.log('Hello from logger provided with Provider class and useClass'); - log = logger.logs[0]; + log = logger.logs.last; } } -////////////////////////////////////////// @Component( selector: 'provider-3', template: '{{log}}', - providers: const [const Provider(Logger, useClass: Logger)] -/* -//#docregion providers-3 - const [provide(Logger, useClass: Logger)] -//#enddocregion providers-3 -*/ -) + providers: const [const Provider(Logger, useClass: Logger)]) class ProviderComponent3 { String log; ProviderComponent3(Logger logger) { logger.log('Hello from logger provided with useClass'); - log = logger.logs[0]; + log = logger.logs.last; } } -////////////////////////////////////////// +@Injectable() class BetterLogger extends Logger {} -@Component(selector: 'provider-4', template: '{{log}}', providers: +@Component( + selector: 'provider-4', + template: '{{log}}', + providers: //#docregion providers-4 -const [const Provider(Logger, useClass: BetterLogger)] + const [const Provider(Logger, useClass: BetterLogger)] //#enddocregion providers-4 ) class ProviderComponent4 { @@ -77,31 +72,32 @@ class ProviderComponent4 { ProviderComponent4(Logger logger) { logger.log('Hello from logger provided with useClass:BetterLogger'); - log = logger.logs[0]; + log = logger.logs.last; } } -////////////////////////////////////////// // #docregion EvenBetterLogger @Injectable() class EvenBetterLogger implements Logger { - UserService _userService; - - List logs = []; + final UserService _userService; + @override List logs = []; EvenBetterLogger(this._userService); - log(String message) { - message = 'Message to ${ _userService.user.name}: ${ message}.'; - print(message); - logs.add(message); + @override void log(String message) { + var msg = 'Message to ${_userService.user.name}: $message.'; + print(msg); + logs.add(msg); } } // #enddocregion EvenBetterLogger -@Component(selector: 'provider-5', template: '{{log}}', providers: +@Component( + selector: 'provider-5', + template: '{{log}}', + providers: //#docregion providers-5 -const [UserService, const Provider(Logger, useClass: EvenBetterLogger)] + const [UserService, const Provider(Logger, useClass: EvenBetterLogger)] //#enddocregion providers-5 ) class ProviderComponent5 { @@ -109,29 +105,30 @@ class ProviderComponent5 { ProviderComponent5(Logger logger) { logger.log('Hello from EvenBetterlogger'); - log = logger.logs[0]; + log = logger.logs.last; } } -////////////////////////////////////////// +@Injectable() class NewLogger extends Logger implements OldLogger {} class OldLogger { List logs = []; - log(String message) { + void log(String message) { throw new Exception('Should not call the old logger!'); } } -@Component(selector: 'provider-6a', template: '{{log}}', providers: -//#docregion providers-6a -const [ - NewLogger, -// Not aliased! Creates two instances of `NewLogger` - const Provider(OldLogger, useClass: NewLogger) -] -//#enddocregion providers-6a +@Component( + selector: 'provider-6a', + template: '{{log}}', + providers: + //#docregion providers-6a + const [NewLogger, + // Not aliased! Creates two instances of `NewLogger` + const Provider(OldLogger, useClass: NewLogger)] + //#enddocregion providers-6a ) class ProviderComponent6a { String log; @@ -144,18 +141,22 @@ class ProviderComponent6a { // The newLogger wasn't called so no logs[] // display the logs of the oldLogger. - log = newLogger.logs == null || newLogger.logs.isEmpty ? oldLogger.logs[0] : newLogger.logs[0]; + log = newLogger.logs == null || newLogger.logs.isEmpty + ? oldLogger.logs[0] + : newLogger.logs[0]; } } -@Component(selector: 'provider-6b', template: '{{log}}', providers: -//#docregion providers-6b -const [ - NewLogger, -// Alias OldLogger w/ reference to NewLogger - const Provider(OldLogger, useExisting: NewLogger) -//#enddocregion providers-6b -]) +@Component( + selector: 'provider-6b', + template: '{{log}}', + providers: + //#docregion providers-6b + const [NewLogger, + // Alias OldLogger with reference to NewLogger + const Provider(OldLogger, useExisting: NewLogger)] + //#enddocregion providers-6b +) class ProviderComponent6b { String log; @@ -167,43 +168,46 @@ class ProviderComponent6b { log = newLogger.logs[0]; } } -////////////////////////////////////////// -// #docregion silent-logger +// #docregion opaque-token +const loggerPrefix = const OpaqueToken('Logger prefix'); +// #enddocregion opaque-token -// An object in the shape of the logger service -class SilentLogger /*implements Logger*/ { - const SilentLogger({this.logs}); +// #docregion configurable-logger +@Injectable() +class ConfigurableLogger extends Logger { + final String _prefix; - final List logs; +// #docregion use-opaque-token + ConfigurableLogger(@Inject(loggerPrefix) this._prefix); +// #enddocregion use-opaque-token - log(String message) {} + @override + void log(String msg) { + super.log('$_prefix: $msg'); + } } +// #enddocregion configurable-logger -const silentLogger = const SilentLogger( - logs: const ['Silent logger says "Shhhhh!". Provided via "useValue"']); -// #enddocregion silent-logger - -@Component(selector: 'provider-7', template: '{{log}}', providers: +@Component(selector: 'provider-7', template: '{{message}}', //#docregion providers-7 -const [const Provider(SilentLogger, useValue: silentLogger)] +providers: const [ + const Provider(Logger, useClass: ConfigurableLogger), +//#docregion providers-usevalue + const Provider(loggerPrefix, useValue: 'Testing') +//#enddocregion providers-usevalue +] //#enddocregion providers-7 -/* -//#docregion providers-7-unchecked -const [const Provider(Logger, useValue: silentLogger)] -//#enddocregion providers-7-unchecked - */ ) class ProviderComponent7 { - String log; + String message; - ProviderComponent7(SilentLogger logger) { - logger.log('Hello from logger provided with useValue'); - log = logger.logs[0]; + ProviderComponent7(Logger logger) { + logger.log('Hello from configurable logger.'); + message = logger.logs.last; } } -///////////////// @Component(selector: 'provider-8', template: '{{log}}', providers: const [ const Provider(HeroService, useFactory: heroServiceFactory), Logger, @@ -219,129 +223,103 @@ class ProviderComponent8 { var log = 'Hero service injected successfully'; } -///////////////// -@Component(selector: 'provider-9a', template: '{{log}}', providers: -/* - // #docregion providers-9a-interface - // WOKRKS! Can use abstract class as provider token - [provide(Config, {useValue: CONFIG})] - // #enddocregion providers-9a-interface - */ - -// #docregion providers-9a -// Use string as provider token -const [const Provider('app.config', useValue: CONFIG_HASH)] -//#enddocregion providers-9a +@Component( + selector: 'provider-9', + template: '{{log}}', + providers: +// #docregion providers-9 +const [const Provider(AppConfig, useValue: config1)] +// #enddocregion providers-9 ) -class ProviderComponent9a implements OnInit { - Config _config; - +class ProviderComponent9 implements OnInit { + AppConfig _config; String log; - /* - // #docregion provider-9a-ctor-interface - // WORKS! Can inject using the abstract class as the parameter type - Config _config; - - ProviderComponent9a(this._config); - // #enddocregion provider-9a-ctor-interface - */ - - // #docregion provider-9a-ctor + ProviderComponent9(AppConfig this._config); - // @Inject(token) to inject the dependency - ProviderComponent9a(@Inject('app.config') Map config) { - _config = new ConfigImpl(apiEndpoint: config['apiEndpoint'], title: config['title']); - } - - // #enddocregion provider-9a-ctor - ngOnInit() { - log = '\'app.config\' Application title is ' + _config.title; + @override + void ngOnInit() { + log = 'appConfigToken Application title is ${_config.title}'; } } -@Component(selector: 'provider-9b', template: '{{log}}', providers: -// #docregion providers-9b -const [const Provider(APP_CONFIG, useValue: CONFIG_HASH)]) // #enddocregion providers-9b -class ProviderComponent9b - implements OnInit { - Config _config; - - String log; - - // #docregion provider-9b-ctor - ProviderComponent9b(@Inject(APP_CONFIG) Map config) { - _config = new ConfigImpl(apiEndpoint: config['apiEndpoint'], title: config['title']); - } - - // #enddocregion provider-9b-ctor - ngOnInit() { - log = 'APP_CONFIG Application title is ' + _config.title; - } -} -////////////////////////////////////////// - // Normal required logger @Component(selector: 'provider-10a', template: '{{log}}', //#docregion providers-logger providers: const [Logger] //#enddocregion providers-logger -) + ) class ProviderComponent10a { String log; ProviderComponent10a(Logger logger) { logger.log('Hello from the required logger.'); - log = logger.logs[0]; + log = logger.logs.last; } } -// Optional logger +// Optional logger, can be null @Component(selector: 'provider-10b', template: '{{log}}') -class ProviderComponent10b implements OnInit { - Logger _logger; - +class ProviderComponent10b { // #docregion provider-10-ctor + final Logger _logger; String log; - ProviderComponent10b(@Optional() this._logger); - + ProviderComponent10b(@Optional() Logger this._logger) { + // . . . // #enddocregion provider-10-ctor - ngOnInit() { - // #docregion provider-10-logger + _logger == null ? log = 'No logger exists' : log = _logger.logs.last; + // #docregion provider-10-ctor + } + // #enddocregion provider-10-ctor +} - // No logger? Make one! - if (_logger == null) { - _logger = new Logger(); - // #enddocregion provider-10-logger - _logger.log('Optional logger was not available.'); - } else { - _logger.log('Hello from the injected logger.'); - log = _logger.logs[0]; - } - log = _logger.logs[0]; +// Optional logger, non null +@Component(selector: 'provider-10c', template: '{{log}}') +class ProviderComponent10c { + // #docregion provider-10-logger + final Logger _logger; + String log; + + ProviderComponent10c(@Optional() Logger logger) : + _logger = logger ?? new DoNothingLogger() { + // . . . + // #enddocregion provider-10-logger + logger == null + ? _logger.log('Optional logger was not available.') + : _logger.log('Hello from the injected logger.'); + log = _logger.logs.last; + // #docregion provider-10-logger } +// #enddocregion provider-10-logger +} + +// #docregion provider-10-logger +// . . . +@Injectable() +class DoNothingLogger extends Logger { + @override List logs = []; + @override void log(String msg) => logs.add(msg); } +// #enddocregion provider-10-logger -///////////////// @Component( selector: 'my-providers', template: ''' -

Provider variations

-
-
-
-
-
-
-
-
-
-
-
-
-
- ''', +

Provider variations

+
+
+
+
+
+
+
+
+
+
+
+
+
''', directives: const [ ProviderComponent1, ProviderComponent2, @@ -352,9 +330,9 @@ class ProviderComponent10b implements OnInit { ProviderComponent6b, ProviderComponent7, ProviderComponent8, - ProviderComponent9a, - ProviderComponent9b, + ProviderComponent9, ProviderComponent10a, - ProviderComponent10b + ProviderComponent10b, + ProviderComponent10c ]) class ProvidersComponent {} diff --git a/public/docs/_examples/dependency-injection/dart/lib/user_service.dart b/public/docs/_examples/dependency-injection/dart/lib/user_service.dart index 682a42b967..5b6cabf960 100644 --- a/public/docs/_examples/dependency-injection/dart/lib/user_service.dart +++ b/public/docs/_examples/dependency-injection/dart/lib/user_service.dart @@ -1,5 +1,4 @@ // #docregion - import 'package:angular2/core.dart'; @Injectable() diff --git a/public/docs/_examples/dependency-injection/dart/pubspec.yaml b/public/docs/_examples/dependency-injection/dart/pubspec.yaml index 6a42a54bd3..d4e3d9b0e8 100644 --- a/public/docs/_examples/dependency-injection/dart/pubspec.yaml +++ b/public/docs/_examples/dependency-injection/dart/pubspec.yaml @@ -5,9 +5,9 @@ version: 0.0.1 environment: sdk: '>=1.13.0 <2.0.0' dependencies: - angular2: 2.0.0-beta.11 + angular2: 2.0.0-beta.13.1 browser: ^0.10.0 - dart_to_js_script_rewriter: ^0.1.0 + dart_to_js_script_rewriter: ^1.0.1 transformers: - angular2: platform_directives: 'package:angular2/common.dart#COMMON_DIRECTIVES' diff --git a/public/docs/_examples/dependency-injection/dart/test/hero_list_component_test.dart b/public/docs/_examples/dependency-injection/dart/test/hero_list_component_test.dart index 0dd76b4f15..1c45babc68 100644 --- a/public/docs/_examples/dependency-injection/dart/test/hero_list_component_test.dart +++ b/public/docs/_examples/dependency-injection/dart/test/hero_list_component_test.dart @@ -1,6 +1,6 @@ // A simple test // More details will be in the testing chapter. -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'package:dependency_injection/heroes/hero.dart'; import 'package:dependency_injection/heroes/hero_list_component.dart'; import 'package:dependency_injection/heroes/hero_service.dart'; @@ -31,4 +31,4 @@ void main() { expect(hlc.heroes.length, expectedHeroes.length); }); } -//#enddocregion spec \ No newline at end of file +//#enddocregion spec diff --git a/public/docs/_examples/dependency-injection/dart/web/index.html b/public/docs/_examples/dependency-injection/dart/web/index.html index dd40fd6c61..cd3dfdb6cf 100644 --- a/public/docs/_examples/dependency-injection/dart/web/index.html +++ b/public/docs/_examples/dependency-injection/dart/web/index.html @@ -1,15 +1,15 @@ - + - - Dependency Injection - - - - - -Loading my-app ... -Loading my-providers ... - + + Dependency Injection + + + + + + Loading... + Loading my-providers ... + diff --git a/public/docs/_examples/dependency-injection/dart/web/main.dart b/public/docs/_examples/dependency-injection/dart/web/main.dart index 8e908cc892..abc5a9c88e 100644 --- a/public/docs/_examples/dependency-injection/dart/web/main.dart +++ b/public/docs/_examples/dependency-injection/dart/web/main.dart @@ -1,6 +1,6 @@ //#docregion - import 'package:angular2/platform/browser.dart'; + import 'package:dependency_injection/app_component.dart'; import 'package:dependency_injection/providers_component.dart'; @@ -9,4 +9,4 @@ main() { bootstrap(AppComponent); //#enddocregion bootstrap bootstrap(ProvidersComponent); -} \ No newline at end of file +} diff --git a/public/docs/_examples/dependency-injection/dart/web/main_1.dart b/public/docs/_examples/dependency-injection/dart/web/main_1.dart index ff9166ccf1..b621869c60 100644 --- a/public/docs/_examples/dependency-injection/dart/web/main_1.dart +++ b/public/docs/_examples/dependency-injection/dart/web/main_1.dart @@ -1,10 +1,10 @@ import 'package:angular2/platform/browser.dart'; import 'package:dependency_injection/app_component.dart'; import 'package:dependency_injection/heroes/hero_service.dart'; -//#docregion bootstrap main() { -// Injecting services in bootstrap works but is discouraged - bootstrap(AppComponent, [HeroService]); -//#enddocregion bootstrap -} \ No newline at end of file + //#docregion bootstrap + bootstrap(AppComponent, + [HeroService]); // DISCOURAGED (but works) + //#enddocregion bootstrap +} diff --git a/public/docs/_examples/dependency-injection/ts/app/injector.component.ts b/public/docs/_examples/dependency-injection/ts/app/injector.component.ts index 300eaee9d3..9914e7d029 100644 --- a/public/docs/_examples/dependency-injection/ts/app/injector.component.ts +++ b/public/docs/_examples/dependency-injection/ts/app/injector.component.ts @@ -12,7 +12,7 @@ import {Logger} from './logger.service'; selector: 'my-injectors', template: `

Other Injections

-
{{car.drive()}}
+
{{car.drive()}}
{{hero.name}}
{{rodent}}
`, diff --git a/public/docs/_examples/displaying-data/dart/lib/app_component.dart b/public/docs/_examples/displaying-data/dart/lib/app_component.dart index 5374ba81a8..a5c04369e7 100644 --- a/public/docs/_examples/displaying-data/dart/lib/app_component.dart +++ b/public/docs/_examples/displaying-data/dart/lib/app_component.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'hero.dart'; diff --git a/public/docs/_examples/displaying-data/dart/lib/app_component_1.dart b/public/docs/_examples/displaying-data/dart/lib/app_component_1.dart index 1991a6645c..20f946fcc5 100644 --- a/public/docs/_examples/displaying-data/dart/lib/app_component_1.dart +++ b/public/docs/_examples/displaying-data/dart/lib/app_component_1.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; @Component( selector: 'my-app', diff --git a/public/docs/_examples/displaying-data/dart/lib/app_component_2.dart b/public/docs/_examples/displaying-data/dart/lib/app_component_2.dart index ff97982532..52162e38e3 100644 --- a/public/docs/_examples/displaying-data/dart/lib/app_component_2.dart +++ b/public/docs/_examples/displaying-data/dart/lib/app_component_2.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; // #docregion mock-heroes const List _heroes = const [ diff --git a/public/docs/_examples/displaying-data/dart/lib/app_component_3.dart b/public/docs/_examples/displaying-data/dart/lib/app_component_3.dart index 9a39808d18..69f424d797 100644 --- a/public/docs/_examples/displaying-data/dart/lib/app_component_3.dart +++ b/public/docs/_examples/displaying-data/dart/lib/app_component_3.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; // #docregion heroes import 'hero.dart'; diff --git a/public/docs/_examples/displaying-data/dart/pubspec.yaml b/public/docs/_examples/displaying-data/dart/pubspec.yaml index b221a9737d..2b84f672ac 100644 --- a/public/docs/_examples/displaying-data/dart/pubspec.yaml +++ b/public/docs/_examples/displaying-data/dart/pubspec.yaml @@ -5,9 +5,9 @@ version: 0.0.1 environment: sdk: '>=1.13.0 <2.0.0' dependencies: - angular2: 2.0.0-beta.11 + angular2: 2.0.0-beta.13.1 browser: ^0.10.0 - dart_to_js_script_rewriter: ^0.1.0 + dart_to_js_script_rewriter: ^1.0.1 transformers: - angular2: platform_directives: 'package:angular2/common.dart#CORE_DIRECTIVES' diff --git a/public/docs/_examples/displaying-data/dart/web/main.dart b/public/docs/_examples/displaying-data/dart/web/main.dart index 69650f0740..6a3620979c 100644 --- a/public/docs/_examples/displaying-data/dart/web/main.dart +++ b/public/docs/_examples/displaying-data/dart/web/main.dart @@ -1,7 +1,8 @@ // #docplaster // #docregion final -import 'package:angular2/bootstrap.dart'; +import 'package:angular2/platform/browser.dart'; // #enddocregion final + //import 'package:displaying_data/app_component_1.dart' as v1; //import 'package:displaying_data/app_component_2.dart' as v2; //import 'package:displaying_data/app_component_3.dart' as v3; diff --git a/public/docs/_examples/forms/dart/lib/hero_form_component.dart b/public/docs/_examples/forms/dart/lib/hero_form_component.dart index 92f82cf0b1..e5d49a08c9 100644 --- a/public/docs/_examples/forms/dart/lib/hero_form_component.dart +++ b/public/docs/_examples/forms/dart/lib/hero_form_component.dart @@ -1,7 +1,7 @@ // #docplaster // #docregion // #docregion no-todo -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'hero.dart'; diff --git a/public/docs/_examples/forms/dart/lib/hero_form_component_initial.dart b/public/docs/_examples/forms/dart/lib/hero_form_component_initial.dart index 3ba6afb443..53a2c20482 100644 --- a/public/docs/_examples/forms/dart/lib/hero_form_component_initial.dart +++ b/public/docs/_examples/forms/dart/lib/hero_form_component_initial.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; @Component(selector: 'hero-form', template: 'Hero form will go here') class HeroFormComponent {} diff --git a/public/docs/_examples/forms/dart/pubspec.yaml b/public/docs/_examples/forms/dart/pubspec.yaml index df6c6dc0c0..fc5c811770 100644 --- a/public/docs/_examples/forms/dart/pubspec.yaml +++ b/public/docs/_examples/forms/dart/pubspec.yaml @@ -5,9 +5,9 @@ version: 0.0.1 environment: sdk: '>=1.13.0 <2.0.0' dependencies: - angular2: 2.0.0-beta.11 + angular2: 2.0.0-beta.13.1 browser: ^0.10.0 - dart_to_js_script_rewriter: ^0.1.0 + dart_to_js_script_rewriter: ^1.0.1 transformers: - angular2: platform_directives: diff --git a/public/docs/_examples/forms/dart/web/main.dart b/public/docs/_examples/forms/dart/web/main.dart index 24a30874e3..7d21d9e9ba 100644 --- a/public/docs/_examples/forms/dart/web/main.dart +++ b/public/docs/_examples/forms/dart/web/main.dart @@ -1,5 +1,6 @@ // #docregion -import 'package:angular2/bootstrap.dart'; +import 'package:angular2/platform/browser.dart'; + import 'package:hero_form/hero_form_component.dart'; main() { diff --git a/public/docs/_examples/hierarchical-dependency-injection/dart/lib/hero.dart b/public/docs/_examples/hierarchical-dependency-injection/dart/lib/hero.dart index 3a9ec96783..d62e5548da 100644 --- a/public/docs/_examples/hierarchical-dependency-injection/dart/lib/hero.dart +++ b/public/docs/_examples/hierarchical-dependency-injection/dart/lib/hero.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; class Hero { String name; diff --git a/public/docs/_examples/hierarchical-dependency-injection/dart/lib/hero_card_component.dart b/public/docs/_examples/hierarchical-dependency-injection/dart/lib/hero_card_component.dart index bb4b2cfd1e..6fa8aeb6cd 100644 --- a/public/docs/_examples/hierarchical-dependency-injection/dart/lib/hero_card_component.dart +++ b/public/docs/_examples/hierarchical-dependency-injection/dart/lib/hero_card_component.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'hero.dart'; diff --git a/public/docs/_examples/hierarchical-dependency-injection/dart/lib/hero_editor_component.dart b/public/docs/_examples/hierarchical-dependency-injection/dart/lib/hero_editor_component.dart index 3619d3ab0d..7ad3226755 100644 --- a/public/docs/_examples/hierarchical-dependency-injection/dart/lib/hero_editor_component.dart +++ b/public/docs/_examples/hierarchical-dependency-injection/dart/lib/hero_editor_component.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'hero.dart'; import 'restore_service.dart'; diff --git a/public/docs/_examples/hierarchical-dependency-injection/dart/lib/heroes_list_component.dart b/public/docs/_examples/hierarchical-dependency-injection/dart/lib/heroes_list_component.dart index 90fbc8e2c4..c484b2091d 100644 --- a/public/docs/_examples/hierarchical-dependency-injection/dart/lib/heroes_list_component.dart +++ b/public/docs/_examples/hierarchical-dependency-injection/dart/lib/heroes_list_component.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'edit_item.dart'; import 'hero.dart'; diff --git a/public/docs/_examples/hierarchical-dependency-injection/dart/lib/heroes_service.dart b/public/docs/_examples/hierarchical-dependency-injection/dart/lib/heroes_service.dart index adc97586ac..c02eeb7539 100644 --- a/public/docs/_examples/hierarchical-dependency-injection/dart/lib/heroes_service.dart +++ b/public/docs/_examples/hierarchical-dependency-injection/dart/lib/heroes_service.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'hero.dart'; diff --git a/public/docs/_examples/hierarchical-dependency-injection/dart/lib/restore_service.dart b/public/docs/_examples/hierarchical-dependency-injection/dart/lib/restore_service.dart index a6d8c59d35..8ddb820f05 100644 --- a/public/docs/_examples/hierarchical-dependency-injection/dart/lib/restore_service.dart +++ b/public/docs/_examples/hierarchical-dependency-injection/dart/lib/restore_service.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; @Injectable() class RestoreService { diff --git a/public/docs/_examples/hierarchical-dependency-injection/dart/pubspec.yaml b/public/docs/_examples/hierarchical-dependency-injection/dart/pubspec.yaml index 550b9c5b31..4f51a27692 100644 --- a/public/docs/_examples/hierarchical-dependency-injection/dart/pubspec.yaml +++ b/public/docs/_examples/hierarchical-dependency-injection/dart/pubspec.yaml @@ -5,9 +5,9 @@ version: 0.0.1 environment: sdk: '>=1.13.0 <2.0.0' dependencies: - angular2: 2.0.0-beta.11 + angular2: 2.0.0-beta.13.1 browser: ^0.10.0 - dart_to_js_script_rewriter: ^0.1.0 + dart_to_js_script_rewriter: ^1.0.1 transformers: - angular2: platform_directives: 'package:angular2/common.dart#COMMON_DIRECTIVES' diff --git a/public/docs/_examples/hierarchical-dependency-injection/dart/web/main.dart b/public/docs/_examples/hierarchical-dependency-injection/dart/web/main.dart index a265c21e69..4b181c2ab5 100644 --- a/public/docs/_examples/hierarchical-dependency-injection/dart/web/main.dart +++ b/public/docs/_examples/hierarchical-dependency-injection/dart/web/main.dart @@ -1,5 +1,6 @@ // #docregion -import 'package:angular2/bootstrap.dart'; +import 'package:angular2/platform/browser.dart'; + import 'package:hierarchical_di/heroes_list_component.dart'; import 'package:hierarchical_di/heroes_service.dart'; diff --git a/public/docs/_examples/homepage-hello-world/ts/index.1.html b/public/docs/_examples/homepage-hello-world/ts/index.1.html index b76916e721..3b747789d7 100644 --- a/public/docs/_examples/homepage-hello-world/ts/index.1.html +++ b/public/docs/_examples/homepage-hello-world/ts/index.1.html @@ -9,14 +9,14 @@ - - + + - - - + + + - + Loading... - \ No newline at end of file + diff --git a/public/docs/_examples/homepage-tabs/ts/index.1.html b/public/docs/_examples/homepage-tabs/ts/index.1.html index a8d306a933..919120928d 100644 --- a/public/docs/_examples/homepage-tabs/ts/index.1.html +++ b/public/docs/_examples/homepage-tabs/ts/index.1.html @@ -10,14 +10,14 @@ - - - + + + - - - + + + - + Loading... - \ No newline at end of file + diff --git a/public/docs/_examples/homepage-todo/ts/app/todo_app.ts b/public/docs/_examples/homepage-todo/ts/app/todo_app.ts index 5688868b73..ca444d4ef6 100644 --- a/public/docs/_examples/homepage-todo/ts/app/todo_app.ts +++ b/public/docs/_examples/homepage-todo/ts/app/todo_app.ts @@ -1,8 +1,8 @@ // #docregion import {Component} from 'angular2/core'; -import {Todo} from './todo'; -import {TodoList} from './todo_list'; -import {TodoForm} from './todo_form'; +import {Todo} from './todo'; +import {TodoList} from './todo_list'; +import {TodoForm} from './todo_form'; @Component({ selector: 'todo-app', @@ -18,19 +18,19 @@ import {TodoForm} from './todo_form'; }) export class TodoApp { todos: Todo[] = [ - {text:'learn angular', done:true}, - {text:'build an angular app', done:false} + {text: 'learn angular', done: true}, + {text: 'build an angular app', done: false} ]; get remaining() { - return this.todos.reduce((count: number, todo: Todo) => count + +!todo.done, 0); + return this.todos.filter(todo => !todo.done).length; } archive(): void { - var oldTodos = this.todos; + let oldTodos = this.todos; this.todos = []; - oldTodos.forEach((todo: Todo) => { - if (!todo.done) this.todos.push(todo); + oldTodos.forEach(todo => { + if (!todo.done) { this.todos.push(todo); } }); } diff --git a/public/docs/_examples/homepage-todo/ts/index.1.html b/public/docs/_examples/homepage-todo/ts/index.1.html index 96ac20053a..03b39cc4f7 100644 --- a/public/docs/_examples/homepage-todo/ts/index.1.html +++ b/public/docs/_examples/homepage-todo/ts/index.1.html @@ -10,14 +10,14 @@ - - - + + + - - - + + + - - - - - Loading... - - diff --git a/public/docs/_examples/quickstart/dart/ex2/pubspec.yaml b/public/docs/_examples/quickstart/dart/pubspec.yaml similarity index 56% rename from public/docs/_examples/quickstart/dart/ex2/pubspec.yaml rename to public/docs/_examples/quickstart/dart/pubspec.yaml index 4211bf2489..f535b32158 100644 --- a/public/docs/_examples/quickstart/dart/ex2/pubspec.yaml +++ b/public/docs/_examples/quickstart/dart/pubspec.yaml @@ -1,14 +1,19 @@ +# #docplaster # #docregion +# #docregion no-rewriter name: angular2_getting_started description: QuickStart version: 0.0.1 environment: sdk: '>=1.13.0 <2.0.0' dependencies: - angular2: 2.0.0-beta.11 + angular2: 2.0.0-beta.13.1 browser: ^0.10.0 - dart_to_js_script_rewriter: ^0.1.0 +# #enddocregion no-rewriter + dart_to_js_script_rewriter: ^1.0.1 +# #docregion no-rewriter transformers: - angular2: entry_points: web/main.dart +# #enddocregion no-rewriter - dart_to_js_script_rewriter diff --git a/public/docs/_examples/quickstart/dart/ex1/web/index.html b/public/docs/_examples/quickstart/dart/web/index.html similarity index 100% rename from public/docs/_examples/quickstart/dart/ex1/web/index.html rename to public/docs/_examples/quickstart/dart/web/index.html diff --git a/public/docs/_examples/quickstart/dart/ex2/web/main.dart b/public/docs/_examples/quickstart/dart/web/main.dart similarity index 63% rename from public/docs/_examples/quickstart/dart/ex2/web/main.dart rename to public/docs/_examples/quickstart/dart/web/main.dart index e6836148a3..3d1f7a3015 100644 --- a/public/docs/_examples/quickstart/dart/ex2/web/main.dart +++ b/public/docs/_examples/quickstart/dart/web/main.dart @@ -1,6 +1,6 @@ // #docregion -import 'package:angular2/angular2.dart'; -import 'package:angular2/bootstrap.dart'; +import 'package:angular2/core.dart'; +import 'package:angular2/platform/browser.dart'; @Component(selector: 'my-app', template: '

My First Angular 2 App

') class AppComponent {} diff --git a/public/docs/_examples/quickstart/js/package.1.json b/public/docs/_examples/quickstart/js/package.1.json index 95d0f6ddba..3c8fe530ea 100644 --- a/public/docs/_examples/quickstart/js/package.1.json +++ b/public/docs/_examples/quickstart/js/package.1.json @@ -7,7 +7,7 @@ }, "license": "ISC", "dependencies": { - "angular2": "2.0.0-beta.12", + "angular2": "2.0.0-beta.14", "es6-shim": "^0.35.0", "reflect-metadata": "0.1.2", "rxjs": "5.0.0-beta.2", @@ -15,6 +15,6 @@ }, "devDependencies": { "concurrently": "^2.0.0", - "lite-server": "^2.1.0" + "lite-server": "^2.2.0" } } diff --git a/public/docs/_examples/quickstart/ts/package.1.json b/public/docs/_examples/quickstart/ts/package.1.json index a11d8ca25f..597a80710d 100644 --- a/public/docs/_examples/quickstart/ts/package.1.json +++ b/public/docs/_examples/quickstart/ts/package.1.json @@ -2,17 +2,17 @@ "name": "angular2-quickstart", "version": "1.0.0", "scripts": { - "start": "concurrently \"npm run tsc:w\" \"npm run lite\" ", + "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ", "tsc": "tsc", "tsc:w": "tsc -w", "lite": "lite-server", "typings": "typings", - "postinstall": "typings install" + "postinstall": "typings install" }, "license": "ISC", "dependencies": { - "angular2": "2.0.0-beta.12", - "systemjs": "0.19.24", + "angular2": "2.0.0-beta.14", + "systemjs": "0.19.25", "es6-shim": "^0.35.0", "reflect-metadata": "0.1.2", "rxjs": "5.0.0-beta.2", @@ -20,8 +20,8 @@ }, "devDependencies": { "concurrently": "^2.0.0", - "lite-server": "^2.1.0", + "lite-server": "^2.2.0", "typescript": "^1.8.9", - "typings":"^0.7.9" + "typings":"^0.7.12" } } diff --git a/public/docs/_examples/server-communication/dart/lib/toh/hero_list_component.dart b/public/docs/_examples/server-communication/dart/lib/toh/hero_list_component.dart index f51a98d35b..89b8714a39 100644 --- a/public/docs/_examples/server-communication/dart/lib/toh/hero_list_component.dart +++ b/public/docs/_examples/server-communication/dart/lib/toh/hero_list_component.dart @@ -1,6 +1,8 @@ // #docregion import 'dart:async'; -import 'package:angular2/angular2.dart'; + +import 'package:angular2/core.dart'; + import 'hero.dart'; import 'hero_service.dart'; diff --git a/public/docs/_examples/server-communication/dart/lib/toh/hero_service.dart b/public/docs/_examples/server-communication/dart/lib/toh/hero_service.dart index f81d45be38..a009d03b7a 100644 --- a/public/docs/_examples/server-communication/dart/lib/toh/hero_service.dart +++ b/public/docs/_examples/server-communication/dart/lib/toh/hero_service.dart @@ -4,7 +4,7 @@ import 'dart:async'; import 'dart:convert'; -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; // #enddocregion v1 // #docregion import-request-options import 'package:http/browser_client.dart'; diff --git a/public/docs/_examples/server-communication/dart/lib/toh/toh_component.dart b/public/docs/_examples/server-communication/dart/lib/toh/toh_component.dart index 3b2a6b27b4..80aff10bdf 100644 --- a/public/docs/_examples/server-communication/dart/lib/toh/toh_component.dart +++ b/public/docs/_examples/server-communication/dart/lib/toh/toh_component.dart @@ -1,4 +1,4 @@ -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'package:http_in_memory_web_api/http_in_memory_web_api.dart'; import 'package:http/browser_client.dart'; import 'package:server_communication/hero_data.dart'; diff --git a/public/docs/_examples/server-communication/dart/lib/wiki/wiki_component.dart b/public/docs/_examples/server-communication/dart/lib/wiki/wiki_component.dart index 78d44f93bc..dce151e834 100644 --- a/public/docs/_examples/server-communication/dart/lib/wiki/wiki_component.dart +++ b/public/docs/_examples/server-communication/dart/lib/wiki/wiki_component.dart @@ -1,6 +1,8 @@ // #docregion import 'dart:async'; -import 'package:angular2/angular2.dart'; + +import 'package:angular2/core.dart'; + import 'wikipedia_service.dart'; @Component( diff --git a/public/docs/_examples/server-communication/dart/lib/wiki/wiki_smart_component.dart b/public/docs/_examples/server-communication/dart/lib/wiki/wiki_smart_component.dart index 3be519471b..6f8934b2f3 100644 --- a/public/docs/_examples/server-communication/dart/lib/wiki/wiki_smart_component.dart +++ b/public/docs/_examples/server-communication/dart/lib/wiki/wiki_smart_component.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'package:stream_transformers/stream_transformers.dart'; import 'wikipedia_service.dart'; diff --git a/public/docs/_examples/server-communication/dart/lib/wiki/wikipedia_service.dart b/public/docs/_examples/server-communication/dart/lib/wiki/wikipedia_service.dart index d4314c3f08..6942f7fa93 100644 --- a/public/docs/_examples/server-communication/dart/lib/wiki/wikipedia_service.dart +++ b/public/docs/_examples/server-communication/dart/lib/wiki/wikipedia_service.dart @@ -1,6 +1,7 @@ // #docregion import 'dart:async'; -import 'package:angular2/angular2.dart'; + +import 'package:angular2/core.dart'; import 'package:jsonpadding/jsonpadding.dart'; @Injectable() diff --git a/public/docs/_examples/server-communication/dart/pubspec.yaml b/public/docs/_examples/server-communication/dart/pubspec.yaml index 3b5c1fce16..fb8bd7e25f 100644 --- a/public/docs/_examples/server-communication/dart/pubspec.yaml +++ b/public/docs/_examples/server-communication/dart/pubspec.yaml @@ -5,9 +5,9 @@ version: 0.0.1 environment: sdk: '>=1.13.0 <2.0.0' dependencies: - angular2: 2.0.0-beta.11 + angular2: 2.0.0-beta.13.1 browser: ^0.10.0 - dart_to_js_script_rewriter: ^0.1.0 + dart_to_js_script_rewriter: ^1.0.1 http: ^0.11.3+3 jsonpadding: ^0.1.0 stream_transformers: ^0.3.0+3 diff --git a/public/docs/_examples/server-communication/dart/web/main.dart b/public/docs/_examples/server-communication/dart/web/main.dart index d0892cf49b..1b7933a87d 100644 --- a/public/docs/_examples/server-communication/dart/web/main.dart +++ b/public/docs/_examples/server-communication/dart/web/main.dart @@ -1,5 +1,6 @@ // #docregion -import 'package:angular2/bootstrap.dart'; +import 'package:angular2/platform/browser.dart'; + import 'package:server_communication/toh/toh_component.dart'; import 'package:server_communication/wiki/wiki_component.dart'; import 'package:server_communication/wiki/wiki_smart_component.dart'; diff --git a/public/docs/_examples/structural-directives/dart/lib/heavy_loader_component.dart b/public/docs/_examples/structural-directives/dart/lib/heavy_loader_component.dart index 647542accc..a2efd3b2f1 100644 --- a/public/docs/_examples/structural-directives/dart/lib/heavy_loader_component.dart +++ b/public/docs/_examples/structural-directives/dart/lib/heavy_loader_component.dart @@ -1,7 +1,7 @@ // #docregion import 'dart:async'; -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; int nextId = 1; diff --git a/public/docs/_examples/structural-directives/dart/lib/structural_directives_component.dart b/public/docs/_examples/structural-directives/dart/lib/structural_directives_component.dart index 477b372bb0..901c8b18b1 100644 --- a/public/docs/_examples/structural-directives/dart/lib/structural_directives_component.dart +++ b/public/docs/_examples/structural-directives/dart/lib/structural_directives_component.dart @@ -1,6 +1,6 @@ // #docplaster // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'heavy_loader_component.dart'; import 'unless_directive.dart'; diff --git a/public/docs/_examples/structural-directives/dart/lib/unless_directive.dart b/public/docs/_examples/structural-directives/dart/lib/unless_directive.dart index 7760658b48..907e0edd15 100644 --- a/public/docs/_examples/structural-directives/dart/lib/unless_directive.dart +++ b/public/docs/_examples/structural-directives/dart/lib/unless_directive.dart @@ -1,7 +1,7 @@ // #docplaster // #docregion // #docregion unless-declaration -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; // #enddocregion unless-declaration // #docregion unless-declaration diff --git a/public/docs/_examples/structural-directives/dart/pubspec.yaml b/public/docs/_examples/structural-directives/dart/pubspec.yaml index 4969b0068e..c131a1eb7f 100644 --- a/public/docs/_examples/structural-directives/dart/pubspec.yaml +++ b/public/docs/_examples/structural-directives/dart/pubspec.yaml @@ -5,9 +5,9 @@ version: 0.0.1 environment: sdk: '>=1.13.0 <2.0.0' dependencies: - angular2: 2.0.0-beta.11 + angular2: 2.0.0-beta.13.1 browser: ^0.10.0 - dart_to_js_script_rewriter: ^0.1.0 + dart_to_js_script_rewriter: ^1.0.1 transformers: - angular2: platform_directives: 'package:angular2/common.dart#CORE_DIRECTIVES' diff --git a/public/docs/_examples/structural-directives/dart/web/main.dart b/public/docs/_examples/structural-directives/dart/web/main.dart index 2c00f66c65..f26456b187 100644 --- a/public/docs/_examples/structural-directives/dart/web/main.dart +++ b/public/docs/_examples/structural-directives/dart/web/main.dart @@ -1,5 +1,6 @@ // #docregion -import 'package:angular2/bootstrap.dart'; +import 'package:angular2/platform/browser.dart'; + import 'package:structural_directives/structural_directives_component.dart'; main() { diff --git a/public/docs/_examples/template-syntax/dart/.docsync.json b/public/docs/_examples/template-syntax/dart/.docsync.json new file mode 100644 index 0000000000..0caee30723 --- /dev/null +++ b/public/docs/_examples/template-syntax/dart/.docsync.json @@ -0,0 +1,4 @@ +{ + "name": "Template Syntax", + "docHref": "https://angular.io/docs/ts/latest/guide/template-syntax.html" +} diff --git a/public/docs/_examples/template-syntax/dart/lib/app_component.dart b/public/docs/_examples/template-syntax/dart/lib/app_component.dart index 0963e28b58..be36d6c38d 100644 --- a/public/docs/_examples/template-syntax/dart/lib/app_component.dart +++ b/public/docs/_examples/template-syntax/dart/lib/app_component.dart @@ -2,7 +2,7 @@ import 'dart:convert'; import 'dart:html'; -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'hero.dart'; import 'hero_detail_component.dart'; diff --git a/public/docs/_examples/template-syntax/dart/lib/hero_detail_component.dart b/public/docs/_examples/template-syntax/dart/lib/hero_detail_component.dart index 80130e0b18..5fd0b1e3cf 100644 --- a/public/docs/_examples/template-syntax/dart/lib/hero_detail_component.dart +++ b/public/docs/_examples/template-syntax/dart/lib/hero_detail_component.dart @@ -1,6 +1,6 @@ // #docplaster // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'hero.dart'; diff --git a/public/docs/_examples/template-syntax/dart/lib/my_click_directive.dart b/public/docs/_examples/template-syntax/dart/lib/my_click_directive.dart index 74299c19c1..0980478f29 100644 --- a/public/docs/_examples/template-syntax/dart/lib/my_click_directive.dart +++ b/public/docs/_examples/template-syntax/dart/lib/my_click_directive.dart @@ -1,7 +1,7 @@ // #docplaster import 'dart:html'; -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; @Directive(selector: '[myClick]') class MyClickDirective { diff --git a/public/docs/_examples/template-syntax/dart/pubspec.yaml b/public/docs/_examples/template-syntax/dart/pubspec.yaml index 2dbd8ae0e4..83a66eb90e 100644 --- a/public/docs/_examples/template-syntax/dart/pubspec.yaml +++ b/public/docs/_examples/template-syntax/dart/pubspec.yaml @@ -5,9 +5,9 @@ version: 0.0.1 environment: sdk: '>=1.13.0 <2.0.0' dependencies: - angular2: 2.0.0-beta.11 + angular2: 2.0.0-beta.13.1 browser: ^0.10.0 - dart_to_js_script_rewriter: ^0.1.0 + dart_to_js_script_rewriter: ^1.0.1 transformers: - angular2: platform_pipes: 'package:angular2/common.dart#COMMON_PIPES' @@ -16,5 +16,3 @@ transformers: - 'package:angular2/common.dart#FORM_DIRECTIVES' entry_points: web/main.dart - dart_to_js_script_rewriter -- $dart2js: - checked: true diff --git a/public/docs/_examples/template-syntax/dart/web/main.dart b/public/docs/_examples/template-syntax/dart/web/main.dart index f1659d0821..1a5f965ec1 100644 --- a/public/docs/_examples/template-syntax/dart/web/main.dart +++ b/public/docs/_examples/template-syntax/dart/web/main.dart @@ -1,5 +1,6 @@ // #docregion -import 'package:angular2/bootstrap.dart'; +import 'package:angular2/platform/browser.dart'; + import 'package:template_syntax/app_component.dart'; void main() { diff --git a/public/docs/_examples/testing/ts/app/app.component.css b/public/docs/_examples/testing/ts/app/app.component.css new file mode 100644 index 0000000000..137e9be7be --- /dev/null +++ b/public/docs/_examples/testing/ts/app/app.component.css @@ -0,0 +1,31 @@ +/* #docplaster */ +/* #docregion css */ +h1 { + font-size: 1.2em; + color: #999; + margin-bottom: 0; +} +h2 { + font-size: 2em; + margin-top: 0; + padding-top: 0; +} +nav a { + padding: 5px 10px; + text-decoration: none; + margin-top: 10px; + display: inline-block; + background-color: #eee; + border-radius: 4px; +} +nav a:visited, a:link { + color: #607D8B; +} +nav a:hover { + color: #039be5; + background-color: #CFD8DC; +} +nav a.router-link-active { + color: #039be5; +} +/* #enddocregion css */ diff --git a/public/docs/_examples/testing/ts/app/app.component.ts b/public/docs/_examples/testing/ts/app/app.component.ts new file mode 100644 index 0000000000..df9985b5ee --- /dev/null +++ b/public/docs/_examples/testing/ts/app/app.component.ts @@ -0,0 +1,59 @@ +// #docplaster +// #docregion +import { Component } from 'angular2/core'; +import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from 'angular2/router'; + +import { HeroService } from './hero.service'; +import { DashboardComponent } from './dashboard.component'; +import { HeroesComponent } from './heroes.component'; +// #docregion hero-detail-import +import { HeroDetailComponent } from './hero-detail.component'; +// #enddocregion hero-detail-import + +@Component({ + selector: 'my-app', +// #docregion template + template: ` +

{{title}}

+ + + `, +// #enddocregion template +// #docregion style-urls + styleUrls: ['app/app.component.css'], +// #enddocregion style-urls + directives: [ROUTER_DIRECTIVES], + providers: [ + ROUTER_PROVIDERS, + HeroService + ] +}) +@RouteConfig([ +// #docregion dashboard-route + { + path: '/dashboard', + name: 'Dashboard', + component: DashboardComponent, + useAsDefault: true + }, +// #enddocregion dashboard-route +// #docregion hero-detail-route + { + path: '/detail/:id', + name: 'HeroDetail', + component: HeroDetailComponent + }, +// #enddocregion hero-detail-route + { + path: '/heroes', + name: 'Heroes', + component: HeroesComponent + } +]) +export class AppComponent { + title = 'Tour of Heroes'; +} +// #enddocregion diff --git a/public/docs/_examples/testing/ts/app/backend.service.ts b/public/docs/_examples/testing/ts/app/backend.service.ts deleted file mode 100644 index 9135af7f5e..0000000000 --- a/public/docs/_examples/testing/ts/app/backend.service.ts +++ /dev/null @@ -1,14 +0,0 @@ -import {Hero} from './hero'; -import {HEROES} from './mock-heroes'; - -let delay = 1000; // ms delay in return of data - -export class BackendService { - - fetchAllHeroesAsync(): Promise { - return new Promise((resolve, reject) => { - // simulate latency by resolving promise after a delay - setTimeout(() => resolve(HEROES.map(h => h.clone())), delay) - }) - } -} diff --git a/public/docs/_examples/testing/ts/app/bootstrap.ts b/public/docs/_examples/testing/ts/app/bootstrap.ts deleted file mode 100644 index f9e6e3e729..0000000000 --- a/public/docs/_examples/testing/ts/app/bootstrap.ts +++ /dev/null @@ -1,11 +0,0 @@ -import {bootstrap} from 'angular2/platform/browser'; - -// Application root component -import {HeroesComponent} from './heroes.component'; - -// Application-wide "injectables"" -import {BackendService} from './backend.service'; -import {HeroService} from './hero.service'; -import {User} from './user'; - -bootstrap(HeroesComponent, [BackendService, HeroService, User]); diff --git a/public/docs/_examples/testing/ts/app/dashboard.component.css b/public/docs/_examples/testing/ts/app/dashboard.component.css new file mode 100644 index 0000000000..ce6e963a5f --- /dev/null +++ b/public/docs/_examples/testing/ts/app/dashboard.component.css @@ -0,0 +1,63 @@ +/* #docplaster */ +/* #docregion */ +[class*='col-'] { + float: left; +} +*, *:after, *:before { + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; +} +h3 { + text-align: center; margin-bottom: 0; +} +[class*='col-'] { + padding-right: 20px; + padding-bottom: 20px; +} +[class*='col-']:last-of-type { + padding-right: 0; +} +.grid { + margin: 0; +} +.col-1-4 { + width: 25%; +} +.module { + padding: 20px; + text-align: center; + color: #eee; + max-height: 120px; + min-width: 120px; + background-color: #607D8B; + border-radius: 2px; +} +h4 { + position: relative; +} +.module:hover { + background-color: #EEE; + cursor: pointer; + color: #607d8b; +} +.grid-pad { + padding: 10px 0; +} +.grid-pad > [class*='col-']:last-of-type { + padding-right: 20px; +} +@media (max-width: 600px) { + .module { + font-size: 10px; + max-height: 75px; } +} +@media (max-width: 1024px) { + .grid { + margin: 0; + } + .module { + min-width: 60px; + } +} +/* #enddocregion */ diff --git a/public/docs/_examples/testing/ts/app/dashboard.component.html b/public/docs/_examples/testing/ts/app/dashboard.component.html new file mode 100644 index 0000000000..a5bafd7702 --- /dev/null +++ b/public/docs/_examples/testing/ts/app/dashboard.component.html @@ -0,0 +1,11 @@ + +

Top Heroes

+
+ +
+ +
+

{{hero.name}}

+
+
+
diff --git a/public/docs/_examples/testing/ts/app/dashboard.component.ts b/public/docs/_examples/testing/ts/app/dashboard.component.ts new file mode 100644 index 0000000000..c4c516a864 --- /dev/null +++ b/public/docs/_examples/testing/ts/app/dashboard.component.ts @@ -0,0 +1,44 @@ +// #docplaster +// #docregion +import { Component, OnInit } from 'angular2/core'; +// #docregion import-router +import { Router } from 'angular2/router'; +// #enddocregion import-router + +import { Hero } from './hero'; +import { HeroService } from './hero.service'; + +@Component({ + selector: 'my-dashboard', + // #docregion template-url + templateUrl: 'app/dashboard.component.html', + // #enddocregion template-url + // #docregion css + styleUrls: ['app/dashboard.component.css'] + // #enddocregion css +}) +// #docregion component +export class DashboardComponent implements OnInit { + + heroes: Hero[] = []; + +// #docregion ctor + constructor( + private _router: Router, + private _heroService: HeroService) { + } +// #enddocregion ctor + + ngOnInit() { + this._heroService.getHeroes() + .then(heroes => this.heroes = heroes.slice(1,5)); + } + + // #docregion goto-detail + gotoDetail(hero: Hero) { + let link = ['HeroDetail', { id: hero.id }]; + this._router.navigate(link); + } + // #enddocregion goto-detail +} +// #enddocregion \ No newline at end of file diff --git a/public/docs/_examples/testing/ts/app/decorators.ts b/public/docs/_examples/testing/ts/app/decorators.ts deleted file mode 100644 index 09f6cd0b15..0000000000 --- a/public/docs/_examples/testing/ts/app/decorators.ts +++ /dev/null @@ -1,16 +0,0 @@ -// @Injectable is a placeholder decorator -// whose sole purpose is to trigger the TS compiler to -// generate the metadata that Angular DI needs for injection. -// -// Metadata generation happens IFF the class has a decorator ... any decorator -// See the `"emitDecoratorMetadata": true` flag in tsconfig.json -// -// For Angular-agnostic classes we can avoid importing from Angular -// and get the metadata generation side-effect -// by creating our own @Injectable decorator - -// for the hip Functional Programmer: -export const Injectable = () => (cls:any) => cls; - -// for everyone else, this is the same thing -//export function Injectable() { return (cls:any) => cls; } \ No newline at end of file diff --git a/public/docs/_examples/testing/ts/app/hero-detail.component.css b/public/docs/_examples/testing/ts/app/hero-detail.component.css index 53d6789226..ab2437efd8 100644 --- a/public/docs/_examples/testing/ts/app/hero-detail.component.css +++ b/public/docs/_examples/testing/ts/app/hero-detail.component.css @@ -1,3 +1,30 @@ -.hero-detail div {padding:0.2em;} -.hero-detail div input {position: absolute; left:9em; } -.hero-id {position: absolute; left:7.5em; } \ No newline at end of file +/* #docregion */ +label { + display: inline-block; + width: 3em; + margin: .5em 0; + color: #607D8B; + font-weight: bold; +} +input { + height: 2em; + font-size: 1em; + padding-left: .4em; +} +button { + margin-top: 20px; + font-family: Arial; + background-color: #eee; + border: none; + padding: 5px 10px; + border-radius: 4px; + cursor: pointer; cursor: hand; +} +button:hover { + background-color: #cfd8dc; +} +button:disabled { + background-color: #eee; + color: #ccc; + cursor: auto; +} diff --git a/public/docs/_examples/testing/ts/app/hero-detail.component.html b/public/docs/_examples/testing/ts/app/hero-detail.component.html index 0de3139b52..cf96fc2169 100644 --- a/public/docs/_examples/testing/ts/app/hero-detail.component.html +++ b/public/docs/_examples/testing/ts/app/hero-detail.component.html @@ -1,24 +1,14 @@ + -
- -

{{hero.name | initCaps}} is {{userName}}'s current super hero!

- -
- - -
-
- {{hero.id}}
-
- - -
-
- - -
-
- - -
-
+
+

{{hero.name}} details!

+
+ {{hero.id}}
+
+ + +
+ + + +
\ No newline at end of file diff --git a/public/docs/_examples/testing/ts/app/hero-detail.component.ts b/public/docs/_examples/testing/ts/app/hero-detail.component.ts index 620eba9a29..1c06a4ee46 100644 --- a/public/docs/_examples/testing/ts/app/hero-detail.component.ts +++ b/public/docs/_examples/testing/ts/app/hero-detail.component.ts @@ -1,35 +1,57 @@ -import {Component, Directive, EventEmitter , ElementRef} from 'angular2/core'; +// #docplaster +// #docregion +// #docregion v2 +// #docregion import-oninit +import { Component, OnInit } from 'angular2/core'; +// #enddocregion import-oninit +// #docregion import-route-params +import {RouteParams} from 'angular2/router'; +// #enddocregion import-route-params -import {Hero} from './hero'; -import {InitCapsPipe} from './init-caps-pipe'; +import { Hero } from './hero'; +// #docregion import-hero-service +import { HeroService } from './hero.service'; +// #enddocregion import-hero-service -@Directive({selector: 'button'}) -class DecoratorDirective { - constructor(el: ElementRef){ - console.log(el) - } -} +// #docregion extract-template @Component({ selector: 'my-hero-detail', + // #docregion template-url templateUrl: 'app/hero-detail.component.html', - inputs: ['hero', 'userName'], // inputs - outputs: ['delete'], // outputs - directives: [DecoratorDirective], + // #enddocregion template-url +// #enddocregion v2 styleUrls: ['app/hero-detail.component.css'], - pipes: [InitCapsPipe] + inputs: ['hero'] +// #docregion v2 }) -export class HeroDetailComponent { - +// #enddocregion extract-template +// #docregion implement +export class HeroDetailComponent implements OnInit { +// #enddocregion implement hero: Hero; - delete = new EventEmitter(); +// #docregion ctor + constructor( + private _heroService: HeroService, + private _routeParams: RouteParams) { + } +// #enddocregion ctor - onDelete() { this.delete.next(this.hero) } +// #docregion ng-oninit + ngOnInit() { + // #docregion get-id + let id = +this._routeParams.get('id'); + // #enddocregion get-id + this._heroService.getHero(id) + .then(hero => this.hero = hero); + } +// #enddocregion ng-oninit - onUpdate() { - if (this.hero) { - this.hero.name += 'x'; - } +// #docregion go-back + goBack() { + window.history.back(); } - userName: string; +// #enddocregion go-back } +// #enddocregion v2 +// #enddocregion diff --git a/public/docs/_examples/testing/ts/app/hero.service.ts b/public/docs/_examples/testing/ts/app/hero.service.ts index 9483e225e7..fb7d0829cb 100644 --- a/public/docs/_examples/testing/ts/app/hero.service.ts +++ b/public/docs/_examples/testing/ts/app/hero.service.ts @@ -1,33 +1,28 @@ -//import {Injectable} from 'angular2/angular2'; // Don't get it from Angular -import {Injectable} from './decorators'; // Use the app's version -import {Hero} from './hero'; -import {BackendService} from './backend.service'; +// #docplaster +// #docregion +import { Hero } from './hero'; +import { HEROES } from './mock-heroes'; +import { Injectable } from 'angular2/core'; @Injectable() export class HeroService { + getHeroes() { + return Promise.resolve(HEROES); + } - heroes: Hero[] = []; // cache of heroes + // See the "Take it slow" appendix + getHeroesSlowly() { + return new Promise(resolve => + setTimeout(()=>resolve(HEROES), 2000) // 2 seconds + ); + } - constructor(protected _backend: BackendService) { } - - refresh() : Promise { // refresh heroes w/ latest from the server - this.heroes.length = 0; - return > this._backend.fetchAllHeroesAsync() - .then(heroes => { - this.heroes.push(...heroes); - return this.heroes; - }) - .catch(e => this._fetchFailed(e)); - } - - protected _fetchFailed(error:any) { - console.error(error); - return Promise.reject(error); - } -} - -// FOR DOCUMENTATION ONLY. NOT USED -interface IHeroService { - heroes : Hero[]; - refresh() : Promise; + //#docregion get-hero + getHero(id: number) { + return Promise.resolve(HEROES).then( + heroes => heroes.filter(hero => hero.id === id)[0] + ); + } + //#enddocregion get-hero } +// #enddocregion \ No newline at end of file diff --git a/public/docs/_examples/testing/ts/app/hero.spec.ts b/public/docs/_examples/testing/ts/app/hero.spec.ts index 103915a9d5..78a73ad6b0 100644 --- a/public/docs/_examples/testing/ts/app/hero.spec.ts +++ b/public/docs/_examples/testing/ts/app/hero.spec.ts @@ -1,17 +1,17 @@ // #docregion // #docplaster // #docregion base-hero-spec -import {Hero} from './hero'; +import { Hero } from './hero'; describe('Hero', () => { - it('has name given in the constructor', () => { - let hero = new Hero(1, 'Super Cat'); + it('has name', () => { + let hero: Hero = {id: 1, name: 'Super Cat'}; expect(hero.name).toEqual('Super Cat'); }); - it('has id given in the constructor', () => { - let hero = new Hero(1, 'Super Cat'); + it('has id', () => { + let hero: Hero = {id: 1, name: 'Super Cat'}; expect(hero.id).toEqual(1); }); // #enddocregion base-hero-spec diff --git a/public/docs/_examples/testing/ts/app/hero.ts b/public/docs/_examples/testing/ts/app/hero.ts index a2ff8002e7..2b89781da5 100644 --- a/public/docs/_examples/testing/ts/app/hero.ts +++ b/public/docs/_examples/testing/ts/app/hero.ts @@ -1,19 +1,5 @@ // #docregion -let nextId = 30; - -export class Hero { - constructor( - public id?: number, - public name?: string, - public power?: string, - public alterEgo?: string - ) { - this.id = id || nextId++; - } - - clone() { return Hero.clone(this); } - - static clone = (h:any) => new Hero(h.id, h.name, h.alterEgo, h.power); - - static setNextId(next:number) { nextId = next; } +export interface Hero { + id: number; + name: string; } diff --git a/public/docs/_examples/testing/ts/app/hero2.ts b/public/docs/_examples/testing/ts/app/hero2.ts deleted file mode 100644 index 840564c4c9..0000000000 --- a/public/docs/_examples/testing/ts/app/hero2.ts +++ /dev/null @@ -1,19 +0,0 @@ -// #docregion -let nextId = 30; - -class Hero { - constructor( - public id?: number, - public name?: string, - public power?: string, - public alterEgo?: string - ) { - this.id = id || nextId++; - } - - clone() { return Hero.clone(this); } - - static clone = (h:any) => new Hero(h.id, h.name, h.alterEgo, h.power); - - static setNextId(next:number) { nextId = next; } -} diff --git a/public/docs/_examples/testing/ts/app/heroes.component.css b/public/docs/_examples/testing/ts/app/heroes.component.css index 38474e6763..d939ab565d 100644 --- a/public/docs/_examples/testing/ts/app/heroes.component.css +++ b/public/docs/_examples/testing/ts/app/heroes.component.css @@ -1,18 +1,59 @@ -.heroes {list-style-type: none; margin-left: 1em; padding: 0; width: 10em;} - -.heroes li { cursor: pointer; position: relative; left: 0; transition: all 0.2s ease; } - -.heroes li:hover {color: #369; background-color: #EEE; left: .2em;} - +.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 0; + height: 1.6em; + border-radius: 4px; +} +.heroes li:hover { + color: #607D8B; + background-color: #DDD; + left: .1em; +} +.heroes li.selected:hover { + background-color: #BBD8DC !important; + color: white; +} +.heroes .text { + position: relative; + top: -3px; +} .heroes .badge { - font-size: small; - color: white; - padding: 0.1em 0.7em; - background-color: #369; - line-height: 1em; - position: relative; - left: -1px; - top: -1px; -} -.selected { background-color: lightblue; color: #369; } -.message {padding: 0.4em 0; font-size: 20px; color: #888} \ No newline at end of file + display: inline-block; + font-size: small; + color: white; + padding: 0.8em 0.7em 0 0.7em; + background-color: #607D8B; + line-height: 1em; + position: relative; + left: -1px; + top: -4px; + height: 1.8em; + margin-right: .8em; + border-radius: 4px 0 0 4px; +} +button { + font-family: Arial; + background-color: #eee; + border: none; + padding: 5px 10px; + border-radius: 4px; + cursor: pointer; + cursor: hand; +} +button:hover { + background-color: #cfd8dc; +} diff --git a/public/docs/_examples/testing/ts/app/heroes.component.html b/public/docs/_examples/testing/ts/app/heroes.component.html index 169dc96b51..9bcd2ba4e8 100644 --- a/public/docs/_examples/testing/ts/app/heroes.component.html +++ b/public/docs/_examples/testing/ts/app/heroes.component.html @@ -1,17 +1,21 @@ -
-

{{userName}}'s Super Heroes

- -
Loading heroes...
-
Pick a hero
    -
  • - {{hero.id}} {{hero.name}} -
  • -
-
-
- - -
+ + +

My Heroes

+
    +
  • + {{hero.id}} {{hero.name}} +
  • +
+ +
+

+ + {{selectedHero.name | uppercase}} is my hero + +

+
+ + diff --git a/public/docs/_examples/testing/ts/app/heroes.component.ts b/public/docs/_examples/testing/ts/app/heroes.component.ts index 9043cbf9a1..6cdb00bc83 100644 --- a/public/docs/_examples/testing/ts/app/heroes.component.ts +++ b/public/docs/_examples/testing/ts/app/heroes.component.ts @@ -1,53 +1,50 @@ -import {Component, OnInit} from 'angular2/core'; -import {HeroDetailComponent} from './hero-detail.component'; -import {HeroService} from './hero.service'; -import {Hero} from './hero'; -import {User} from './user'; +// #docplaster +// #docregion +import { Component, OnInit } from 'angular2/core'; +import { Router } from 'angular2/router'; +import { Hero } from './hero'; +import { HeroDetailComponent } from './hero-detail.component'; +import { HeroService } from './hero.service'; + +// #docregion metadata +// #docregion heroes-component-renaming @Component({ selector: 'my-heroes', +// #enddocregion heroes-component-renaming templateUrl: 'app/heroes.component.html', - directives: [HeroDetailComponent], - styleUrls: ['app/heroes.component.css'] + styleUrls: ['app/heroes.component.css'], + directives: [HeroDetailComponent] +// #docregion heroes-component-renaming }) +// #enddocregion heroes-component-renaming +// #enddocregion metadata +// #docregion class +// #docregion heroes-component-renaming export class HeroesComponent implements OnInit { - heroes: Hero[] = []; - currentHero: Hero; - userName: string; - - constructor(private _heroService: HeroService, private _user: User) { - this.userName = this._user.name || 'someone'; - } +// #enddocregion heroes-component-renaming + heroes: Hero[]; + selectedHero: Hero; - getSelectedClass(hero: Hero) {return { selected: hero === this.currentHero }}; + constructor( + private _router: Router, + private _heroService: HeroService) { } - onDelete(hero?: Hero) { - hero = hero || this.currentHero; - let i = this.heroes.indexOf(hero); - if (i > -1) { - this.heroes.splice(i, 1); - } - this.currentHero = this.heroes[i] || this.heroes[i - 1]; + getHeroes() { + this._heroService.getHeroes().then(heroes => this.heroes = heroes); } - ngOnInit(){ - this.heroes = this.onRefresh(); + ngOnInit() { + this.getHeroes(); } - onRefresh() { - //console.log('Refreshing heroes'); - // clear the decks - this.currentHero = undefined; - this.heroes = []; - - this._heroService.refresh() - .then(heroes => this.heroes = heroes); - - return this.heroes; - } + onSelect(hero: Hero) { this.selectedHero = hero; } - onSelect(hero: Hero) { - this.currentHero = hero; - console.log(`Hero selected: ` + JSON.stringify(hero)); + gotoDetail() { + this._router.navigate(['HeroDetail', { id: this.selectedHero.id }]); } +// #docregion heroes-component-renaming } +// #enddocregion heroes-component-renaming +// #enddocregion class +// #enddocregion \ No newline at end of file diff --git a/public/docs/_examples/testing/ts/app/init-caps-pipe.spec.ts b/public/docs/_examples/testing/ts/app/init-caps-pipe.spec.ts deleted file mode 100644 index 2dd78f22ca..0000000000 --- a/public/docs/_examples/testing/ts/app/init-caps-pipe.spec.ts +++ /dev/null @@ -1,39 +0,0 @@ -// #docregion -// #docplaster -// #docregion base-pipe-spec -import {InitCapsPipe} from './init-caps-pipe'; - -describe('InitCapsPipe', () => { - let pipe:InitCapsPipe; - - beforeEach(() => { - pipe = new InitCapsPipe(); - }); - - it('transforms "abc" to "Abc"', () => { - expect(pipe.transform('abc')).toEqual('Abc'); - }); - - it('transforms "abc def" to "Abc Def"', () => { - expect(pipe.transform('abc def')).toEqual('Abc Def'); - }); - - it('leaves "Abc Def" unchanged', () => { - expect(pipe.transform('Abc Def')).toEqual('Abc Def'); - }); - // #enddocregion base-pipe-spec - - /* more tests we could run - - it('transforms "abc-def" to "Abc-def"', () => { - expect(pipe.transform('abc-def')).toEqual('Abc-def'); - }); - - it('transforms " abc def" to " Abc Def" (preserves spaces) ', () => { - expect(pipe.transform(' abc def')).toEqual(' Abc Def'); - }); - - */ - // #docregion base-pipe-spec -}); -// #enddocregion base-pipe-spec diff --git a/public/docs/_examples/testing/ts/app/init-caps-pipe.ts b/public/docs/_examples/testing/ts/app/init-caps-pipe.ts deleted file mode 100644 index cceb823c19..0000000000 --- a/public/docs/_examples/testing/ts/app/init-caps-pipe.ts +++ /dev/null @@ -1,15 +0,0 @@ -// #docregion -// #docregion depends-on-angular -import {Pipe, PipeTransform} from 'angular2/core'; - -@Pipe({ name: 'initCaps' }) -export class InitCapsPipe implements PipeTransform { - // #enddocregion depends-on-angular - transform(value: string) { - return value.toLowerCase().replace(/(?:^|\s)[a-z]/g, function(m) { - return m.toUpperCase(); - }); - } - // #docregion depends-on-angular -} -// #enddocregion depends-on-angular diff --git a/public/docs/_examples/testing/ts/app/main.ts b/public/docs/_examples/testing/ts/app/main.ts new file mode 100644 index 0000000000..c469e18fd0 --- /dev/null +++ b/public/docs/_examples/testing/ts/app/main.ts @@ -0,0 +1,4 @@ +import { bootstrap } from 'angular2/platform/browser'; +import { AppComponent } from './app.component'; + +bootstrap(AppComponent); \ No newline at end of file diff --git a/public/docs/_examples/testing/ts/app/mock-heroes.ts b/public/docs/_examples/testing/ts/app/mock-heroes.ts index 11b9e8ff73..cdcba35097 100644 --- a/public/docs/_examples/testing/ts/app/mock-heroes.ts +++ b/public/docs/_examples/testing/ts/app/mock-heroes.ts @@ -1,70 +1,16 @@ -import {Hero} from './hero'; +// #docregion +import { Hero } from './hero'; export var HEROES: Hero[] = [ - { - "id": 11, - "name": "Mr. Nice", - "alterEgo": "Walter Meek", - "power": "Empathy" - }, - { - "id": 12, - "name": "Narco", - "alterEgo": "Nancy Knight", - "power": "Drowsiness" - }, - { - "id": 13, - "name": "Bombasto", - "alterEgo": "Bob LaRue", - "power": "Hypersound" - }, - { - "id": 14, - "name": "Celeritas", - "alterEgo": "Larry Plodder", - "power": "Super speed" - }, - { - "id": 15, - "name": "Magneta", - "alterEgo": "Julie Ohm", - "power": "Master of electro-magnetic fields" - }, - { - "id": 16, - "name": "Rubber Man", - "alterEgo": "Jimmy Longfellow", - "power": "Super flexible" - }, - { - "id": 17, - "name": "Dynama", - "alterEgo": "Shirley Knots", - "power": "Incredible strength" - }, - { - "id": 18, - "name": "Dr IQ", - "alterEgo": "Chuck Overstreet", - "power": "Really smart" - }, - { - "id": 19, - "name": "Magma", - "alterEgo": "Harvey Klue", - "power": "Super hot" - }, - { - "id": 20, - "name": "Tornado", - "alterEgo": "Ted Baxter", - "power": "Weather changer" - }, - { - "id": 21, - "name": "eeny weenie", - "alterEgo": "Ima Small", - "power": "shrink to infinitesimal size" - } - ].map(h => Hero.clone(h)); \ No newline at end of file + {"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"} +]; +// #enddocregion \ No newline at end of file diff --git a/public/docs/_examples/testing/ts/app/my-uppercase.pipe.1.ts b/public/docs/_examples/testing/ts/app/my-uppercase.pipe.1.ts new file mode 100644 index 0000000000..4914151579 --- /dev/null +++ b/public/docs/_examples/testing/ts/app/my-uppercase.pipe.1.ts @@ -0,0 +1,9 @@ +// #docregion +import {Pipe, PipeTransform} from 'angular2/core'; + +@Pipe({ name: 'my-uppercase' }) +export class MyUppercasePipe implements PipeTransform { + transform(value: string) { + return value; + } +} diff --git a/public/docs/_examples/testing/ts/app/my-uppercase.pipe.spec.ts b/public/docs/_examples/testing/ts/app/my-uppercase.pipe.spec.ts new file mode 100644 index 0000000000..fc9952f6b2 --- /dev/null +++ b/public/docs/_examples/testing/ts/app/my-uppercase.pipe.spec.ts @@ -0,0 +1,41 @@ +// #docregion +// #docplaster +// #docregion base-pipe-spec +import { MyUppercasePipe } from './my-uppercase.pipe'; + +describe('MyUppercasePipe', () => { + let pipe : MyUppercasePipe; + + beforeEach(() => { + pipe = new MyUppercasePipe(); + }); + + // #docregion expectations + it('transforms "abc" to "ABC"', () => { + expect(pipe.transform('abc')).toEqual('ABC'); + }); + + it('transforms "abc def" to "ABC DEF"', () => { + expect(pipe.transform('abc def')).toEqual('ABC DEF'); + }); + + it('leaves "ABC DEF" unchanged', () => { + expect(pipe.transform('ABC DEF')).toEqual('ABC DEF'); + }); + // #enddocregion expectations + // #enddocregion base-pipe-spec + + /* more tests we could run + + it('transforms "abc-def" to "Abc-def"', () => { + expect(pipe.transform('abc-def')).toEqual('Abc-def'); + }); + + it('transforms " abc def" to " Abc Def" (preserves spaces) ', () => { + expect(pipe.transform(' abc def')).toEqual(' Abc Def'); + }); + + */ + // #docregion base-pipe-spec +}); +// #enddocregion base-pipe-spec diff --git a/public/docs/_examples/testing/ts/app/my-uppercase.pipe.ts b/public/docs/_examples/testing/ts/app/my-uppercase.pipe.ts new file mode 100644 index 0000000000..4b51e14091 --- /dev/null +++ b/public/docs/_examples/testing/ts/app/my-uppercase.pipe.ts @@ -0,0 +1,13 @@ +// #docregion +// #docregion depends-on-angular +import {Pipe, PipeTransform} from 'angular2/core'; +// #enddocregion depends-on-angular + +@Pipe({ name: 'my-uppercase' }) +export class MyUppercasePipe implements PipeTransform { + // #docregion uppercase + transform(value: string) { + return value.toUpperCase(); + } + // #enddocregion uppercase +} diff --git a/public/docs/_examples/testing/ts/app/hero-detail.component.spec.ts.not-yet b/public/docs/_examples/testing/ts/app/old-specs/hero-detail.component.spec.ts.not-yet similarity index 100% rename from public/docs/_examples/testing/ts/app/hero-detail.component.spec.ts.not-yet rename to public/docs/_examples/testing/ts/app/old-specs/hero-detail.component.spec.ts.not-yet diff --git a/public/docs/_examples/testing/ts/app/hero-detail.component.wrapped-tests.spec.ts.not-yet b/public/docs/_examples/testing/ts/app/old-specs/hero-detail.component.wrapped-tests.spec.ts.not-yet similarity index 100% rename from public/docs/_examples/testing/ts/app/hero-detail.component.wrapped-tests.spec.ts.not-yet rename to public/docs/_examples/testing/ts/app/old-specs/hero-detail.component.wrapped-tests.spec.ts.not-yet diff --git a/public/docs/_examples/testing/ts/app/hero.service.ng.spec.ts b/public/docs/_examples/testing/ts/app/old-specs/hero.service.ng.spec.ts.not-yet similarity index 100% rename from public/docs/_examples/testing/ts/app/hero.service.ng.spec.ts rename to public/docs/_examples/testing/ts/app/old-specs/hero.service.ng.spec.ts.not-yet diff --git a/public/docs/_examples/testing/ts/app/hero.service.no-ng.1.spec.ts b/public/docs/_examples/testing/ts/app/old-specs/hero.service.no-ng.1.spec.ts.not-yet similarity index 100% rename from public/docs/_examples/testing/ts/app/hero.service.no-ng.1.spec.ts rename to public/docs/_examples/testing/ts/app/old-specs/hero.service.no-ng.1.spec.ts.not-yet diff --git a/public/docs/_examples/testing/ts/app/hero.service.no-ng.spec.ts b/public/docs/_examples/testing/ts/app/old-specs/hero.service.no-ng.spec.ts.not-yet similarity index 100% rename from public/docs/_examples/testing/ts/app/hero.service.no-ng.spec.ts rename to public/docs/_examples/testing/ts/app/old-specs/hero.service.no-ng.spec.ts.not-yet diff --git a/public/docs/_examples/testing/ts/app/heroes.component.ng.spec.ts.not-yet b/public/docs/_examples/testing/ts/app/old-specs/heroes.component.ng.spec.ts.not-yet similarity index 100% rename from public/docs/_examples/testing/ts/app/heroes.component.ng.spec.ts.not-yet rename to public/docs/_examples/testing/ts/app/old-specs/heroes.component.ng.spec.ts.not-yet diff --git a/public/docs/_examples/testing/ts/app/heroes.component.no-ng.spec.ts b/public/docs/_examples/testing/ts/app/old-specs/heroes.component.no-ng.spec.ts.not-yet similarity index 100% rename from public/docs/_examples/testing/ts/app/heroes.component.no-ng.spec.ts rename to public/docs/_examples/testing/ts/app/old-specs/heroes.component.no-ng.spec.ts.not-yet diff --git a/public/docs/_examples/testing/ts/app/user.spec.ts b/public/docs/_examples/testing/ts/app/old-specs/user.spec.ts.not-yet similarity index 100% rename from public/docs/_examples/testing/ts/app/user.spec.ts rename to public/docs/_examples/testing/ts/app/old-specs/user.spec.ts.not-yet diff --git a/public/docs/_examples/testing/ts/app/user.ts b/public/docs/_examples/testing/ts/app/user.ts deleted file mode 100644 index 247979c59a..0000000000 --- a/public/docs/_examples/testing/ts/app/user.ts +++ /dev/null @@ -1,6 +0,0 @@ -// imagine this is the result of a login -export class User { - id = 42; - name = 'Bongo'; - email = 'bongo@amazing.io' -}; diff --git a/public/docs/_examples/testing/ts/index.html b/public/docs/_examples/testing/ts/index.html index 44e37b274f..0e91f05760 100644 --- a/public/docs/_examples/testing/ts/index.html +++ b/public/docs/_examples/testing/ts/index.html @@ -1,27 +1,39 @@ + + + + + + Angular 2 Tour of Heroes + - - - - - - - - - - + + + + + + + + + - - - - + + + + + + + + + + + + Loading... + diff --git a/public/docs/_examples/testing/ts/unit-tests-0.html b/public/docs/_examples/testing/ts/unit-tests-0.html index fd73c1d2e0..af7d1b9192 100644 --- a/public/docs/_examples/testing/ts/unit-tests-0.html +++ b/public/docs/_examples/testing/ts/unit-tests-0.html @@ -6,11 +6,11 @@ Ng App Unit Tests - + - - - + + + diff --git a/public/docs/_examples/testing/ts/unit-tests-1.html b/public/docs/_examples/testing/ts/unit-tests-1.html index 90b8335bd2..b370ca053a 100644 --- a/public/docs/_examples/testing/ts/unit-tests-1.html +++ b/public/docs/_examples/testing/ts/unit-tests-1.html @@ -4,11 +4,11 @@ Ng App Unit Tests - + - - - + + + diff --git a/public/docs/_examples/testing/ts/unit-tests-2.html b/public/docs/_examples/testing/ts/unit-tests-2.html index c7e22db334..d47b4d1f60 100644 --- a/public/docs/_examples/testing/ts/unit-tests-2.html +++ b/public/docs/_examples/testing/ts/unit-tests-2.html @@ -6,11 +6,11 @@ Ng App Unit Tests - + - - - + + + diff --git a/public/docs/_examples/testing/ts/unit-tests-3.html b/public/docs/_examples/testing/ts/unit-tests-3.html index 708f8d0e94..6f6ce4a7c8 100644 --- a/public/docs/_examples/testing/ts/unit-tests-3.html +++ b/public/docs/_examples/testing/ts/unit-tests-3.html @@ -6,16 +6,16 @@ Ng App Unit Tests - - - + + + - - + + - - + + + - - - - - - - - + + + + + + + @@ -36,7 +35,7 @@ // #3. Import the spec files explicitly Promise.all([ System.import('app/hero.spec'), - System.import('app/init-caps-pipe.spec') + System.import('app/my-uppercase.pipe.spec') ]) // #4. wait for all imports to load ... diff --git a/public/docs/_examples/testing/ts/unit-tests-5.html b/public/docs/_examples/testing/ts/unit-tests-5.html new file mode 100644 index 0000000000..909716200c --- /dev/null +++ b/public/docs/_examples/testing/ts/unit-tests-5.html @@ -0,0 +1,50 @@ + + + + + + Ng App Unit Tests + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/docs/_examples/testing/ts/unit-tests-5.html.not-yet b/public/docs/_examples/testing/ts/unit-tests-5.html.not-yet deleted file mode 100644 index df8e3704ba..0000000000 --- a/public/docs/_examples/testing/ts/unit-tests-5.html.not-yet +++ /dev/null @@ -1,44 +0,0 @@ - - - - - - Ng App Unit Tests - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/public/docs/_examples/testing/ts/unit-tests-6.html.not-yet b/public/docs/_examples/testing/ts/unit-tests-6.html.not-yet index d5449711ee..df8e3704ba 100644 --- a/public/docs/_examples/testing/ts/unit-tests-6.html.not-yet +++ b/public/docs/_examples/testing/ts/unit-tests-6.html.not-yet @@ -9,37 +9,35 @@ + + + - - - - - diff --git a/public/docs/_examples/testing/ts/unit-tests-7.html.not-yet b/public/docs/_examples/testing/ts/unit-tests-7.html.not-yet new file mode 100644 index 0000000000..d5449711ee --- /dev/null +++ b/public/docs/_examples/testing/ts/unit-tests-7.html.not-yet @@ -0,0 +1,46 @@ + + + + + + Ng App Unit Tests + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/public/docs/_examples/toh-1/ts-snippets/app.component.snippets.pt1.ts b/public/docs/_examples/toh-1/ts-snippets/app.component.snippets.pt1.ts index ffcc45d2f6..a62447ad91 100644 --- a/public/docs/_examples/toh-1/ts-snippets/app.component.snippets.pt1.ts +++ b/public/docs/_examples/toh-1/ts-snippets/app.component.snippets.pt1.ts @@ -33,13 +33,13 @@ template:` // #docregion app-component-1 export class AppComponent { - public title = 'Tour of Heroes'; - public hero = 'Windstorm'; + title = 'Tour of Heroes'; + hero = 'Windstorm'; } // #enddocregion app-component-1 // #docregion hero-property-1 -public hero: Hero = { +hero: Hero = { id: 1, name: 'Windstorm' }; diff --git a/public/docs/_examples/toh-1/ts/app/app.component.ts b/public/docs/_examples/toh-1/ts/app/app.component.ts index 59074565e7..227d901e9b 100644 --- a/public/docs/_examples/toh-1/ts/app/app.component.ts +++ b/public/docs/_examples/toh-1/ts/app/app.component.ts @@ -1,12 +1,12 @@ // #docregion pt1 import {Component} from 'angular2/core'; -// #docregion hero-interface-1 -interface Hero { +// #docregion hero-class-1 +export class Hero { id: number; name: string; } -// #enddocregion hero-interface-1 +// #enddocregion hero-class-1 @Component({ selector: 'my-app', @@ -21,8 +21,8 @@ interface Hero { ` }) export class AppComponent { - public title = 'Tour of Heroes'; - public hero: Hero = { + title = 'Tour of Heroes'; + hero: Hero = { id: 1, name: 'Windstorm' }; diff --git a/public/docs/_examples/toh-2/ts/app/app.component.ts b/public/docs/_examples/toh-2/ts/app/app.component.ts index cf719e6589..cb1c1e918f 100644 --- a/public/docs/_examples/toh-2/ts/app/app.component.ts +++ b/public/docs/_examples/toh-2/ts/app/app.component.ts @@ -1,7 +1,7 @@ // #docregion pt2 import {Component} from 'angular2/core'; -interface Hero { +export class Hero { id: number; name: string; } @@ -37,7 +37,7 @@ interface Hero { margin: 0 0 2em 0; list-style-type: none; padding: 0; - width: 10em; + width: 15em; } .heroes li { cursor: pointer; diff --git a/public/docs/_examples/toh-3/ts/app/app.component.ts b/public/docs/_examples/toh-3/ts/app/app.component.ts index d0fdea50e1..7d63d295bc 100644 --- a/public/docs/_examples/toh-3/ts/app/app.component.ts +++ b/public/docs/_examples/toh-3/ts/app/app.component.ts @@ -32,7 +32,7 @@ import {HeroDetailComponent} from './hero-detail.component'; margin: 0 0 2em 0; list-style-type: none; padding: 0; - width: 10em; + width: 15em; } .heroes li { cursor: pointer; diff --git a/public/docs/_examples/toh-3/ts/app/hero-detail.component.ts b/public/docs/_examples/toh-3/ts/app/hero-detail.component.ts index 90b47c0996..12ebad0f1e 100644 --- a/public/docs/_examples/toh-3/ts/app/hero-detail.component.ts +++ b/public/docs/_examples/toh-3/ts/app/hero-detail.component.ts @@ -1,7 +1,8 @@ // #docplaster // #docregion // #docregion v1 -import {Component} from 'angular2/core'; +import {Component, Input} from 'angular2/core'; + // #enddocregion v1 // #docregion hero-import import {Hero} from './hero'; @@ -10,7 +11,7 @@ import {Hero} from './hero'; // #docregion v1 @Component({ selector: 'my-hero-detail', -// #enddocregion v1 +// #enddocregion v1 // #docregion template template: `
@@ -21,18 +22,18 @@ import {Hero} from './hero';
- `, + ` // #enddocregion template - // #docregion inputs - inputs: ['hero'] - // #enddocregion inputs -// #docregion v1 +// #docregion v1 }) export class HeroDetailComponent { // #enddocregion v1 -// #docregion hero +// #docregion hero-input + @Input() +// #docregion hero hero: Hero; -// #enddocregion hero +// #enddocregion hero +// #enddocregion hero-input // #docregion v1 } // #enddocregion v1 diff --git a/public/docs/_examples/toh-3/ts/app/hero.ts b/public/docs/_examples/toh-3/ts/app/hero.ts index ed746da042..f4b0cd6b35 100644 --- a/public/docs/_examples/toh-3/ts/app/hero.ts +++ b/public/docs/_examples/toh-3/ts/app/hero.ts @@ -1,5 +1,5 @@ // #docregion -export interface Hero { +export class Hero { id: number; name: string; } diff --git a/public/docs/_examples/toh-4/ts/app/app.component.ts b/public/docs/_examples/toh-4/ts/app/app.component.ts index bc587e2390..4505e515a1 100644 --- a/public/docs/_examples/toh-4/ts/app/app.component.ts +++ b/public/docs/_examples/toh-4/ts/app/app.component.ts @@ -32,7 +32,7 @@ import {HeroService} from './hero.service'; margin: 0 0 2em 0; list-style-type: none; padding: 0; - width: 10em; + width: 15em; } .heroes li { cursor: pointer; diff --git a/public/docs/_examples/toh-4/ts/app/hero-detail.component.ts b/public/docs/_examples/toh-4/ts/app/hero-detail.component.ts index 72024f533a..2a17aafd39 100644 --- a/public/docs/_examples/toh-4/ts/app/hero-detail.component.ts +++ b/public/docs/_examples/toh-4/ts/app/hero-detail.component.ts @@ -1,5 +1,5 @@ // #docregion -import {Component} from 'angular2/core'; +import {Component, Input} from 'angular2/core'; import {Hero} from './hero'; @Component({ @@ -15,9 +15,8 @@ import {Hero} from './hero'; - `, - inputs: ['hero'] + ` }) export class HeroDetailComponent { - hero: Hero; + @Input() hero: Hero; } diff --git a/public/docs/_examples/toh-4/ts/app/hero.ts b/public/docs/_examples/toh-4/ts/app/hero.ts index a61b497759..e3eac516da 100644 --- a/public/docs/_examples/toh-4/ts/app/hero.ts +++ b/public/docs/_examples/toh-4/ts/app/hero.ts @@ -1,4 +1,4 @@ -export interface Hero { +export class Hero { id: number; name: string; } diff --git a/public/docs/_examples/toh-5/dart/lib/app_component.dart b/public/docs/_examples/toh-5/dart/lib/app_component.dart index 9af70e7ebe..60ebd7c9bc 100644 --- a/public/docs/_examples/toh-5/dart/lib/app_component.dart +++ b/public/docs/_examples/toh-5/dart/lib/app_component.dart @@ -1,6 +1,6 @@ // #docplaster // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'package:angular2/router.dart'; import 'package:angular2_tour_of_heroes/heroes_component.dart'; diff --git a/public/docs/_examples/toh-5/dart/lib/app_component_1.dart b/public/docs/_examples/toh-5/dart/lib/app_component_1.dart index 3a109d2321..da03cbbee0 100644 --- a/public/docs/_examples/toh-5/dart/lib/app_component_1.dart +++ b/public/docs/_examples/toh-5/dart/lib/app_component_1.dart @@ -1,6 +1,6 @@ // #docplaster // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; // #enddocregion import 'package:angular2/router.dart'; // for testing only // #docregion diff --git a/public/docs/_examples/toh-5/dart/lib/app_component_2.dart b/public/docs/_examples/toh-5/dart/lib/app_component_2.dart index d0b6854c0f..a677520d91 100644 --- a/public/docs/_examples/toh-5/dart/lib/app_component_2.dart +++ b/public/docs/_examples/toh-5/dart/lib/app_component_2.dart @@ -1,6 +1,6 @@ // #docplaster // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; // #docregion import-router import 'package:angular2/router.dart'; // #enddocregion import-router diff --git a/public/docs/_examples/toh-5/dart/lib/dashboard_component.dart b/public/docs/_examples/toh-5/dart/lib/dashboard_component.dart index bd5d6f2caf..76335c54c4 100644 --- a/public/docs/_examples/toh-5/dart/lib/dashboard_component.dart +++ b/public/docs/_examples/toh-5/dart/lib/dashboard_component.dart @@ -1,6 +1,6 @@ // #docplaster // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; // #docregion import-router import 'package:angular2/router.dart'; // #enddocregion import-router diff --git a/public/docs/_examples/toh-5/dart/lib/dashboard_component_1.dart b/public/docs/_examples/toh-5/dart/lib/dashboard_component_1.dart index 0839105b8c..5324624d1f 100644 --- a/public/docs/_examples/toh-5/dart/lib/dashboard_component_1.dart +++ b/public/docs/_examples/toh-5/dart/lib/dashboard_component_1.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; @Component( selector: 'my-dashboard', diff --git a/public/docs/_examples/toh-5/dart/lib/dashboard_component_2.dart b/public/docs/_examples/toh-5/dart/lib/dashboard_component_2.dart index a91eddf22c..fa1dd9a41e 100644 --- a/public/docs/_examples/toh-5/dart/lib/dashboard_component_2.dart +++ b/public/docs/_examples/toh-5/dart/lib/dashboard_component_2.dart @@ -1,6 +1,6 @@ // #docplaster // #docregion imports -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'hero.dart'; import 'hero_service.dart'; diff --git a/public/docs/_examples/toh-5/dart/lib/hero_detail_component.dart b/public/docs/_examples/toh-5/dart/lib/hero_detail_component.dart index c92b9981d6..ec143efb62 100644 --- a/public/docs/_examples/toh-5/dart/lib/hero_detail_component.dart +++ b/public/docs/_examples/toh-5/dart/lib/hero_detail_component.dart @@ -4,7 +4,7 @@ import 'dart:html'; // #docregion import-oninit -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; // #enddocregion import-oninit // #docregion import-route-params import 'package:angular2/router.dart'; diff --git a/public/docs/_examples/toh-5/dart/lib/hero_service.dart b/public/docs/_examples/toh-5/dart/lib/hero_service.dart index eb6cc9f7f0..97490fd5fa 100644 --- a/public/docs/_examples/toh-5/dart/lib/hero_service.dart +++ b/public/docs/_examples/toh-5/dart/lib/hero_service.dart @@ -3,7 +3,7 @@ // #docregion import 'dart:async'; -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'hero.dart'; import 'mock_heroes.dart'; diff --git a/public/docs/_examples/toh-5/dart/lib/heroes_component.dart b/public/docs/_examples/toh-5/dart/lib/heroes_component.dart index 2cfc0fcbab..d615756952 100644 --- a/public/docs/_examples/toh-5/dart/lib/heroes_component.dart +++ b/public/docs/_examples/toh-5/dart/lib/heroes_component.dart @@ -2,7 +2,7 @@ // #docregion import 'dart:async'; -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'package:angular2/router.dart'; import 'hero.dart'; diff --git a/public/docs/_examples/toh-5/dart/pubspec.yaml b/public/docs/_examples/toh-5/dart/pubspec.yaml index 274d8224fd..58420a4d1f 100644 --- a/public/docs/_examples/toh-5/dart/pubspec.yaml +++ b/public/docs/_examples/toh-5/dart/pubspec.yaml @@ -5,14 +5,12 @@ version: 0.0.1 environment: sdk: '>=1.13.0 <2.0.0' dependencies: - angular2: 2.0.0-beta.11 + angular2: 2.0.0-beta.13.1 browser: ^0.10.0 - dart_to_js_script_rewriter: ^0.1.0+4 + dart_to_js_script_rewriter: ^1.0.1 transformers: - angular2: platform_directives: package:angular2/common.dart#COMMON_DIRECTIVES platform_pipes: package:angular2/common.dart#COMMON_PIPES entry_points: web/main.dart - dart_to_js_script_rewriter -- $dart2js: - checked: true diff --git a/public/docs/_examples/toh-5/dart/web/main.dart b/public/docs/_examples/toh-5/dart/web/main.dart index 5983c199f7..314d6f0b65 100644 --- a/public/docs/_examples/toh-5/dart/web/main.dart +++ b/public/docs/_examples/toh-5/dart/web/main.dart @@ -1,4 +1,4 @@ -import 'package:angular2/bootstrap.dart'; +import 'package:angular2/platform/browser.dart'; import 'package:angular2_tour_of_heroes/app_component.dart'; diff --git a/public/docs/_examples/toh-5/ts/app/hero-detail.component.ts b/public/docs/_examples/toh-5/ts/app/hero-detail.component.ts index 1c06a4ee46..31cb07858c 100644 --- a/public/docs/_examples/toh-5/ts/app/hero-detail.component.ts +++ b/public/docs/_examples/toh-5/ts/app/hero-detail.component.ts @@ -2,10 +2,10 @@ // #docregion // #docregion v2 // #docregion import-oninit -import { Component, OnInit } from 'angular2/core'; +import { Component, Input, OnInit } from 'angular2/core'; // #enddocregion import-oninit // #docregion import-route-params -import {RouteParams} from 'angular2/router'; +import { RouteParams } from 'angular2/router'; // #enddocregion import-route-params import { Hero } from './hero'; @@ -20,15 +20,14 @@ import { HeroService } from './hero.service'; templateUrl: 'app/hero-detail.component.html', // #enddocregion template-url // #enddocregion v2 - styleUrls: ['app/hero-detail.component.css'], - inputs: ['hero'] + styleUrls: ['app/hero-detail.component.css'] // #docregion v2 }) // #enddocregion extract-template // #docregion implement export class HeroDetailComponent implements OnInit { // #enddocregion implement - hero: Hero; + @Input() hero: Hero; // #docregion ctor constructor( diff --git a/public/docs/_examples/toh-5/ts/app/hero.ts b/public/docs/_examples/toh-5/ts/app/hero.ts index a61b497759..e3eac516da 100644 --- a/public/docs/_examples/toh-5/ts/app/hero.ts +++ b/public/docs/_examples/toh-5/ts/app/hero.ts @@ -1,4 +1,4 @@ -export interface Hero { +export class Hero { id: number; name: string; } diff --git a/public/docs/_examples/toh-5/ts/app/heroes.component.css b/public/docs/_examples/toh-5/ts/app/heroes.component.css index d939ab565d..35e45af98d 100644 --- a/public/docs/_examples/toh-5/ts/app/heroes.component.css +++ b/public/docs/_examples/toh-5/ts/app/heroes.component.css @@ -6,7 +6,7 @@ margin: 0 0 2em 0; list-style-type: none; padding: 0; - width: 10em; + width: 15em; } .heroes li { cursor: pointer; diff --git a/public/docs/_examples/toh-6/e2e-spec.js b/public/docs/_examples/toh-6/e2e-spec.js new file mode 100644 index 0000000000..02d5b2a698 --- /dev/null +++ b/public/docs/_examples/toh-6/e2e-spec.js @@ -0,0 +1,133 @@ +describe('TOH Http Chapter', function () { + + beforeEach(function () { + browser.get(''); + }); + + function getPageStruct() { + hrefEles = element.all(by.css('my-app a')); + + return { + hrefs: hrefEles, + myDashboardHref: hrefEles.get(0), + myDashboardParent: element(by.css('my-app my-dashboard')), + topHeroes: element.all(by.css('my-app my-dashboard .module.hero')), + + myHeroesHref: hrefEles.get(1), + myHeroesParent: element(by.css('my-app my-heroes')), + allHeroes: element.all(by.css('my-app my-heroes li .hero-element')), + + firstDeleteButton: element.all(by.buttonText('Delete')).get(0), + + addButton: element.all(by.buttonText('Add New Hero')).get(0), + + heroDetail: element(by.css('my-app my-hero-detail')) + } + } + + it('should be able to add a hero from the "Heroes" view', function(){ + var page = getPageStruct(); + var heroCount; + + page.myHeroesHref.click().then(function() { + browser.waitForAngular(); + heroCount = page.allHeroes.count(); + expect(heroCount).toBe(4, 'should show 4'); + }).then(function() { + return page.addButton.click(); + }).then(function(){ + return save(page,'','The New Hero'); + }).then(function(){ + browser.waitForAngular(); + + heroCount = page.allHeroes.count(); + expect(heroCount).toBe(5, 'should show 5'); + + var newHero = element(by.xpath('//span[@class="hero-element" and contains(text(),"The New Hero")]')); + expect(newHero).toBeDefined(); + }); + }); + + it('should be able to delete hero from "Heroes" view', function(){ + var page = getPageStruct(); + var heroCount; + + page.myHeroesHref.click().then(function() { + browser.waitForAngular(); + heroCount = page.allHeroes.count(); + expect(heroCount).toBe(4, 'should show 4'); + }).then(function() { + return page.firstDeleteButton.click(); + }).then(function(){ + browser.waitForAngular(); + heroCount = page.allHeroes.count(); + expect(heroCount).toBe(3, 'should show 3'); + }); + }); + + it('should be able to save details from "Dashboard" view', function () { + var page = getPageStruct(); + expect(page.myDashboardParent.isPresent()).toBe(true, 'dashboard element should be available'); + var heroEle = page.topHeroes.get(2); + var heroDescrEle = heroEle.element(by.css('h4')); + var heroDescr; + + return heroDescrEle.getText().then(function(text) { + heroDescr = text; + return heroEle.click(); + }).then(function() { + return save(page, heroDescr, '-foo'); + }) + .then(function(){ + return page.myDashboardHref.click(); + }) + .then(function() { + expect(page.myDashboardParent.isPresent()).toBe(true, 'dashboard element should be back'); + expect(heroDescrEle.getText()).toEqual(heroDescr + '-foo'); + }); + }); + + it('should be able to save details from "Heroes" view', function () { + var page = getPageStruct(); + + var viewDetailsButtonEle = page.myHeroesParent.element(by.cssContainingText('button', 'View Details')); + var heroEle, heroDescr; + + page.myHeroesHref.click().then(function() { + expect(page.myDashboardParent.isPresent()).toBe(false, 'dashboard element should NOT be present'); + expect(page.myHeroesParent.isPresent()).toBe(true, 'myHeroes element should be present'); + expect(viewDetailsButtonEle.isPresent()).toBe(false, 'viewDetails button should not yet be present'); + heroEle = page.allHeroes.get(0); + return heroEle.getText(); + }).then(function(text) { + // remove leading 'id' from the element + heroDescr = text.substr(text.indexOf(' ')+1); + return heroEle.click(); + }).then(function() { + expect(viewDetailsButtonEle.isDisplayed()).toBe(true, 'viewDetails button should now be visible'); + return viewDetailsButtonEle.click(); + }).then(function() { + return save(page, heroDescr, '-bar'); + }) + .then(function(){ + return page.myHeroesHref.click(); + }) + .then(function() { + expect(heroEle.getText()).toContain(heroDescr + '-bar'); + }); + }); + + function save(page, origValue, textToAdd) { + var inputEle = page.heroDetail.element(by.css('input')); + expect(inputEle.isDisplayed()).toBe(true, 'should be able to see the input box'); + var saveButtonEle = page.heroDetail.element(by.buttonText('Save')); + var backButtonEle = page.heroDetail.element(by.buttonText('Back')); + expect(backButtonEle.isDisplayed()).toBe(true, 'should be able to see the back button'); + var detailTextEle = page.heroDetail.element(by.css('div h2')); + expect(detailTextEle.getText()).toContain(origValue); + return sendKeys(inputEle, textToAdd).then(function () { + expect(detailTextEle.getText()).toContain(origValue + textToAdd); + return saveButtonEle.click(); + }); + } +}); diff --git a/public/docs/_examples/toh-6/ts/.gitignore b/public/docs/_examples/toh-6/ts/.gitignore new file mode 100644 index 0000000000..2cb7d2a2e9 --- /dev/null +++ b/public/docs/_examples/toh-6/ts/.gitignore @@ -0,0 +1 @@ +**/*.js diff --git a/public/docs/_examples/toh-6/ts/app/app.component.css b/public/docs/_examples/toh-6/ts/app/app.component.css new file mode 100644 index 0000000000..137e9be7be --- /dev/null +++ b/public/docs/_examples/toh-6/ts/app/app.component.css @@ -0,0 +1,31 @@ +/* #docplaster */ +/* #docregion css */ +h1 { + font-size: 1.2em; + color: #999; + margin-bottom: 0; +} +h2 { + font-size: 2em; + margin-top: 0; + padding-top: 0; +} +nav a { + padding: 5px 10px; + text-decoration: none; + margin-top: 10px; + display: inline-block; + background-color: #eee; + border-radius: 4px; +} +nav a:visited, a:link { + color: #607D8B; +} +nav a:hover { + color: #039be5; + background-color: #CFD8DC; +} +nav a.router-link-active { + color: #039be5; +} +/* #enddocregion css */ diff --git a/public/docs/_examples/toh-6/ts/app/app.component.ts b/public/docs/_examples/toh-6/ts/app/app.component.ts new file mode 100644 index 0000000000..5fffc240ee --- /dev/null +++ b/public/docs/_examples/toh-6/ts/app/app.component.ts @@ -0,0 +1,62 @@ +// #docplaster +// #docregion +import { Component } from 'angular2/core'; +import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from 'angular2/router'; + +import { HeroService } from './hero.service'; +import { DashboardComponent } from './dashboard.component'; +import { HeroesComponent } from './heroes.component'; +import { HeroDetailComponent } from './hero-detail.component'; + +import { provide } from 'angular2/core'; +import { XHRBackend } from 'angular2/http'; +import { HTTP_PROVIDERS } from 'angular2/http'; + +import { InMemoryBackendService, SEED_DATA } from 'a2-in-memory-web-api/core'; +import { HeroData } from './hero-data'; + +@Component({ + selector: 'my-app', + + template: ` +

{{title}}

+ + + `, + styleUrls: ['app/app.component.css'], + directives: [ROUTER_DIRECTIVES], + providers: [ + ROUTER_PROVIDERS, + HeroService, + + HTTP_PROVIDERS, + HeroService, + // in-memory web api providers + provide(XHRBackend, { useClass: InMemoryBackendService }), // in-mem server + provide(SEED_DATA, { useClass: HeroData }) // in-mem server data + ] +}) +@RouteConfig([ + { + path: '/dashboard', + name: 'Dashboard', + component: DashboardComponent, + useAsDefault: true + }, + { + path: '/detail/:id', + name: 'HeroDetail', + component: HeroDetailComponent + }, + { + path: '/heroes', + name: 'Heroes', + component: HeroesComponent + } +]) +export class AppComponent { + title = 'Tour of Heroes'; +} diff --git a/public/docs/_examples/toh-6/ts/app/dashboard.component.css b/public/docs/_examples/toh-6/ts/app/dashboard.component.css new file mode 100644 index 0000000000..ce6e963a5f --- /dev/null +++ b/public/docs/_examples/toh-6/ts/app/dashboard.component.css @@ -0,0 +1,63 @@ +/* #docplaster */ +/* #docregion */ +[class*='col-'] { + float: left; +} +*, *:after, *:before { + -webkit-box-sizing: border-box; + -moz-box-sizing: border-box; + box-sizing: border-box; +} +h3 { + text-align: center; margin-bottom: 0; +} +[class*='col-'] { + padding-right: 20px; + padding-bottom: 20px; +} +[class*='col-']:last-of-type { + padding-right: 0; +} +.grid { + margin: 0; +} +.col-1-4 { + width: 25%; +} +.module { + padding: 20px; + text-align: center; + color: #eee; + max-height: 120px; + min-width: 120px; + background-color: #607D8B; + border-radius: 2px; +} +h4 { + position: relative; +} +.module:hover { + background-color: #EEE; + cursor: pointer; + color: #607d8b; +} +.grid-pad { + padding: 10px 0; +} +.grid-pad > [class*='col-']:last-of-type { + padding-right: 20px; +} +@media (max-width: 600px) { + .module { + font-size: 10px; + max-height: 75px; } +} +@media (max-width: 1024px) { + .grid { + margin: 0; + } + .module { + min-width: 60px; + } +} +/* #enddocregion */ diff --git a/public/docs/_examples/toh-6/ts/app/dashboard.component.html b/public/docs/_examples/toh-6/ts/app/dashboard.component.html new file mode 100644 index 0000000000..a5bafd7702 --- /dev/null +++ b/public/docs/_examples/toh-6/ts/app/dashboard.component.html @@ -0,0 +1,11 @@ + +

Top Heroes

+
+ +
+ +
+

{{hero.name}}

+
+
+
diff --git a/public/docs/_examples/toh-6/ts/app/dashboard.component.ts b/public/docs/_examples/toh-6/ts/app/dashboard.component.ts new file mode 100644 index 0000000000..541817c3fd --- /dev/null +++ b/public/docs/_examples/toh-6/ts/app/dashboard.component.ts @@ -0,0 +1,32 @@ +// #docplaster +// #docregion +import { Component, OnInit } from 'angular2/core'; +import { Router } from 'angular2/router'; + +import { Hero } from './hero'; +import { HeroService } from './hero.service'; + +@Component({ + selector: 'my-dashboard', + templateUrl: 'app/dashboard.component.html', + styleUrls: ['app/dashboard.component.css'] +}) +export class DashboardComponent implements OnInit { + + heroes: Hero[] = []; + + constructor( + private _router: Router, + private _heroService: HeroService) { + } + + ngOnInit() { + this._heroService.getHeroes() + .then(heroes => this.heroes = heroes.slice(1,5)); + } + + gotoDetail(hero: Hero) { + let link = ['HeroDetail', { id: hero.id }]; + this._router.navigate(link); + } +} diff --git a/public/docs/_examples/toh-6/ts/app/hero-data.ts b/public/docs/_examples/toh-6/ts/app/hero-data.ts new file mode 100644 index 0000000000..18c4617149 --- /dev/null +++ b/public/docs/_examples/toh-6/ts/app/hero-data.ts @@ -0,0 +1,12 @@ +// #docregion +export class HeroData { + createDb() { + let heroes = [ + { "id": 1, "name": "Windstorm" }, + { "id": 2, "name": "Bombasto" }, + { "id": 3, "name": "Magneta" }, + { "id": 4, "name": "Tornado" } + ]; + return {heroes}; + } +} \ No newline at end of file diff --git a/public/docs/_examples/toh-6/ts/app/hero-detail.component.css b/public/docs/_examples/toh-6/ts/app/hero-detail.component.css new file mode 100644 index 0000000000..ab2437efd8 --- /dev/null +++ b/public/docs/_examples/toh-6/ts/app/hero-detail.component.css @@ -0,0 +1,30 @@ +/* #docregion */ +label { + display: inline-block; + width: 3em; + margin: .5em 0; + color: #607D8B; + font-weight: bold; +} +input { + height: 2em; + font-size: 1em; + padding-left: .4em; +} +button { + margin-top: 20px; + font-family: Arial; + background-color: #eee; + border: none; + padding: 5px 10px; + border-radius: 4px; + cursor: pointer; cursor: hand; +} +button:hover { + background-color: #cfd8dc; +} +button:disabled { + background-color: #eee; + color: #ccc; + cursor: auto; +} diff --git a/public/docs/_examples/toh-6/ts/app/hero-detail.component.html b/public/docs/_examples/toh-6/ts/app/hero-detail.component.html new file mode 100644 index 0000000000..f532eb0109 --- /dev/null +++ b/public/docs/_examples/toh-6/ts/app/hero-detail.component.html @@ -0,0 +1,13 @@ + + +
+

{{hero.name}} details!

+
+ {{hero.id}}
+
+ + +
+ + +
\ No newline at end of file diff --git a/public/docs/_examples/toh-6/ts/app/hero-detail.component.ts b/public/docs/_examples/toh-6/ts/app/hero-detail.component.ts new file mode 100644 index 0000000000..98038fc19d --- /dev/null +++ b/public/docs/_examples/toh-6/ts/app/hero-detail.component.ts @@ -0,0 +1,46 @@ +// #docplaster +// #docregion +import { Component, Input, Output, OnInit, EventEmitter } from 'angular2/core'; +import { RouteParams } from 'angular2/router'; + +import { Hero } from './hero'; +import { HeroService } from './hero.service'; +@Component({ + selector: 'my-hero-detail', + templateUrl: 'app/hero-detail.component.html', + styleUrls: ['app/hero-detail.component.css'] +}) +export class HeroDetailComponent implements OnInit { + @Input() hero: Hero; + @Output() updateHeroes = new EventEmitter(); + + constructor( + private _heroService: HeroService, + private _routeParams: RouteParams) { + } + + // #docregion ngOnInit + ngOnInit() { + if(this._routeParams.get('id') !== null){ + let id = +this._routeParams.get('id'); + this._heroService.getHero(id) + .then(hero => this.hero = hero); + } + else{ + this.hero = new Hero(); + } + } + // #enddocregion ngOnInit + // #docregion save + save(){ + this._heroService.save(this.hero) + .then(r => { + this.updateHeroes.emit(r); + }); + } + // #enddocregion save + goBack() { + window.history.back(); + } +} + diff --git a/public/docs/_examples/toh-6/ts/app/hero.service.ts b/public/docs/_examples/toh-6/ts/app/hero.service.ts new file mode 100644 index 0000000000..767ff4e189 --- /dev/null +++ b/public/docs/_examples/toh-6/ts/app/hero.service.ts @@ -0,0 +1,79 @@ +// #docplaster +// #docregion +import { Hero } from './hero'; +import { Injectable } from 'angular2/core'; +import { Http, Response, Headers } from 'angular2/http'; + +@Injectable() +export class HeroService { + + private _heroesUrl = 'app/heroes'; // URL to web api + + constructor(private _http:Http){ + } + + //#docregion get-heroes + getHeroes() { + return this._http.get(this._heroesUrl).toPromise() + .then((res:Response) => res.json()) + .then(res => res.data) + .catch(this.handleError); + } + //#enddocregion get-heroes + + getHero(id: number) { + return this.getHeroes().then( + heroes => heroes.filter((hero:Hero) => hero.id === id)[0] + ); + } + + save(hero:Hero){ + if(hero.id){ + return this.put(hero); + } + else{ + return this.post(hero); + } + } + + delete(hero:Hero){ + //#docregion delete-hero + let headers = new Headers(); + headers.append('Content-Type', 'application/json'); + + let url = `${this._heroesUrl}/${hero.id}`; + + return this._http.delete(url,headers).toPromise() + .catch(this.handleError); + //#enddocregion delete-hero + } + + private post(hero:Hero){ + //#docregion post-hero + let headers = new Headers(); + headers.append('Content-Type', 'application/json'); + + return this._http.post(this._heroesUrl, JSON.stringify(hero), {headers:headers}).toPromise() + .catch(this.handleError); + //#enddocregion post-hero + } + + private put(hero:Hero){ + //#docregion put-hero + let headers = new Headers(); + headers.append('Content-Type', 'application/json'); + + let url = `${this._heroesUrl}/${hero.id}`; + + return this._http.put(url, JSON.stringify(hero), {headers:headers}).toPromise() + .catch(this.handleError); + //#enddocregion put-hero + } + + //#docregion error-handler + private handleError(error:any){ + console.log('An error occurred:' + error); + } + //#enddocregion error-handler +} +// #enddocregion \ No newline at end of file diff --git a/public/docs/_examples/toh-6/ts/app/hero.ts b/public/docs/_examples/toh-6/ts/app/hero.ts new file mode 100644 index 0000000000..e3eac516da --- /dev/null +++ b/public/docs/_examples/toh-6/ts/app/hero.ts @@ -0,0 +1,4 @@ +export class Hero { + id: number; + name: string; +} diff --git a/public/docs/_examples/toh-6/ts/app/heroes.component.css b/public/docs/_examples/toh-6/ts/app/heroes.component.css new file mode 100644 index 0000000000..35e45af98d --- /dev/null +++ b/public/docs/_examples/toh-6/ts/app/heroes.component.css @@ -0,0 +1,59 @@ +.selected { + background-color: #CFD8DC !important; + color: white; +} +.heroes { + margin: 0 0 2em 0; + list-style-type: none; + padding: 0; + width: 15em; +} +.heroes li { + cursor: pointer; + position: relative; + left: 0; + background-color: #EEE; + margin: .5em; + padding: .3em 0; + height: 1.6em; + border-radius: 4px; +} +.heroes li:hover { + color: #607D8B; + background-color: #DDD; + left: .1em; +} +.heroes li.selected:hover { + background-color: #BBD8DC !important; + color: white; +} +.heroes .text { + position: relative; + top: -3px; +} +.heroes .badge { + display: inline-block; + font-size: small; + color: white; + padding: 0.8em 0.7em 0 0.7em; + background-color: #607D8B; + line-height: 1em; + position: relative; + left: -1px; + top: -4px; + height: 1.8em; + margin-right: .8em; + border-radius: 4px 0 0 4px; +} +button { + font-family: Arial; + background-color: #eee; + border: none; + padding: 5px 10px; + border-radius: 4px; + cursor: pointer; + cursor: hand; +} +button:hover { + background-color: #cfd8dc; +} diff --git a/public/docs/_examples/toh-6/ts/app/heroes.component.html b/public/docs/_examples/toh-6/ts/app/heroes.component.html new file mode 100644 index 0000000000..060def3d39 --- /dev/null +++ b/public/docs/_examples/toh-6/ts/app/heroes.component.html @@ -0,0 +1,22 @@ + + +

My Heroes

+
    +
  • + + {{hero.id}} {{hero.name}} + + +
  • +
+ + +
+ +
+
+

+ {{selectedHero.name | uppercase}} is my hero +

+ +
diff --git a/public/docs/_examples/toh-6/ts/app/heroes.component.ts b/public/docs/_examples/toh-6/ts/app/heroes.component.ts new file mode 100644 index 0000000000..125140be0f --- /dev/null +++ b/public/docs/_examples/toh-6/ts/app/heroes.component.ts @@ -0,0 +1,58 @@ +// #docplaster +// #docregion +import { Component, OnInit } from 'angular2/core'; +import { Router } from 'angular2/router'; + +import { Hero } from './hero'; +import { HeroDetailComponent } from './hero-detail.component'; +import { HeroService } from './hero.service'; + +@Component({ + selector: 'my-heroes', + templateUrl: 'app/heroes.component.html', + styleUrls: ['app/heroes.component.css'], + directives: [HeroDetailComponent] +}) +export class HeroesComponent implements OnInit { + heroes: Hero[]; + selectedHero: Hero; + addingHero = false; + + constructor( + private _router: Router, + private _heroService: HeroService) { } + + getHeroes() { + this._heroService.getHeroes() + .then(heroes => this.heroes = heroes); + } + + addHero(){ + this.addingHero = true; + this.selectedHero = null; + } + + // #docregion delete + delete(hero:Hero, event:any){ + event.stopPropagation(); + this._heroService.delete(hero) + .then(r => { + this.heroes = this.heroes.filter(h => h.id !== hero.id); + } + ); + } + // #enddocregion delete + + ngOnInit() { + this.getHeroes(); + } + + onSelect(hero: Hero) { + this.selectedHero = hero; + this.addingHero = false; + } + + gotoDetail() { + this._router.navigate(['HeroDetail', { id: this.selectedHero.id }]); + } +} diff --git a/public/docs/_examples/toh-6/ts/app/main.ts b/public/docs/_examples/toh-6/ts/app/main.ts new file mode 100644 index 0000000000..cc1b80d9a9 --- /dev/null +++ b/public/docs/_examples/toh-6/ts/app/main.ts @@ -0,0 +1,6 @@ +import { bootstrap } from 'angular2/platform/browser'; +import { AppComponent } from './app.component'; + +import 'rxjs/Rx'; + +bootstrap(AppComponent); \ No newline at end of file diff --git a/public/docs/_examples/toh-6/ts/example-config.json b/public/docs/_examples/toh-6/ts/example-config.json new file mode 100644 index 0000000000..e69de29bb2 diff --git a/public/docs/_examples/toh-6/ts/index.html b/public/docs/_examples/toh-6/ts/index.html new file mode 100644 index 0000000000..90c5acaa27 --- /dev/null +++ b/public/docs/_examples/toh-6/ts/index.html @@ -0,0 +1,36 @@ + + + + + Angular 2 Tour of Heroes + + + + + + + + + + + + + + + + + + + + + + + + + Loading... + + diff --git a/public/docs/_examples/toh-6/ts/plnkr.json b/public/docs/_examples/toh-6/ts/plnkr.json new file mode 100644 index 0000000000..777d9ad1f1 --- /dev/null +++ b/public/docs/_examples/toh-6/ts/plnkr.json @@ -0,0 +1,9 @@ +{ + "description": "Tour of Heroes: Part 6", + "files":[ + "!**/*.d.ts", + "!**/*.js", + "!**/*.[1,2].*" + ], + "tags": ["tutorial", "tour", "heroes", "http"] +} diff --git a/public/docs/_examples/toh-6/ts/sample.css b/public/docs/_examples/toh-6/ts/sample.css new file mode 100644 index 0000000000..042f0494f6 --- /dev/null +++ b/public/docs/_examples/toh-6/ts/sample.css @@ -0,0 +1,8 @@ +button.delete-button{ + float:right; + background-color: gray !important; + color:white; +} + + + diff --git a/public/docs/_examples/tslint.json b/public/docs/_examples/tslint.json new file mode 100644 index 0000000000..276453f4f5 --- /dev/null +++ b/public/docs/_examples/tslint.json @@ -0,0 +1,93 @@ +{ + "rules": { + "class-name": true, + "comment-format": [ + true, + "check-space" + ], + "curly": true, + "eofline": true, + "forin": true, + "indent": [ + true, + "spaces" + ], + "label-position": true, + "label-undefined": true, + "max-line-length": [ + true, + 140 + ], + "member-access": false, + "member-ordering": [ + true, + "static-before-instance", + "variables-before-functions" + ], + "no-arg": true, + "no-bitwise": true, + "no-console": [ + true, + "debug", + "info", + "time", + "timeEnd", + "trace" + ], + "no-construct": true, + "no-debugger": true, + "no-duplicate-key": true, + "no-duplicate-variable": true, + "no-empty": false, + "no-eval": true, + "no-inferrable-types": true, + "no-shadowed-variable": true, + "no-string-literal": false, + "no-switch-case-fall-through": true, + "no-trailing-whitespace": true, + "no-unused-expression": true, + "no-unused-variable": true, + "no-unreachable": true, + "no-use-before-declare": true, + "no-var-keyword": true, + "object-literal-sort-keys": false, + "one-line": [ + true, + "check-open-brace", + "check-catch", + "check-else", + "check-whitespace" + ], + "quotemark": [ + true, + "single" + ], + "radix": true, + "semicolon": [ + "always" + ], + "triple-equals": [ + true, + "allow-null-check" + ], + "typedef-whitespace": [ + true, + { + "call-signature": "nospace", + "index-signature": "nospace", + "parameter": "nospace", + "property-declaration": "nospace", + "variable-declaration": "nospace" + } + ], + "variable-name": false, + "whitespace": [ + true, + "check-branch", + "check-decl", + "check-operator", + "check-separator", + "check-type" + ] + } +} diff --git a/public/docs/_examples/tutorial/ts/app/app.component.ts b/public/docs/_examples/tutorial/ts/app/app.component.ts index 1cea6e8f9c..8e0bf4403d 100644 --- a/public/docs/_examples/tutorial/ts/app/app.component.ts +++ b/public/docs/_examples/tutorial/ts/app/app.component.ts @@ -26,5 +26,5 @@ import {HeroService} from './hero.service'; {path: '/detail/:id', name: 'HeroDetail', component: HeroDetailComponent} ]) export class AppComponent { - public title = 'Tour of Heroes'; + title = 'Tour of Heroes'; } diff --git a/public/docs/_examples/tutorial/ts/app/dashboard.component.ts b/public/docs/_examples/tutorial/ts/app/dashboard.component.ts index ae5f048a57..f5a3719563 100644 --- a/public/docs/_examples/tutorial/ts/app/dashboard.component.ts +++ b/public/docs/_examples/tutorial/ts/app/dashboard.component.ts @@ -9,7 +9,7 @@ import {HeroService} from './hero.service'; styleUrls: ['app/dashboard.component.css'] }) export class DashboardComponent implements OnInit { - public heroes: Hero[] = []; + heroes: Hero[] = []; constructor(private _heroService: HeroService, private _router: Router) { } diff --git a/public/docs/_examples/tutorial/ts/app/hero-detail.component.ts b/public/docs/_examples/tutorial/ts/app/hero-detail.component.ts index 0014918b8b..22f2e5222e 100644 --- a/public/docs/_examples/tutorial/ts/app/hero-detail.component.ts +++ b/public/docs/_examples/tutorial/ts/app/hero-detail.component.ts @@ -1,4 +1,4 @@ -import {Component, OnInit} from 'angular2/core'; +import {Component, Input, OnInit} from 'angular2/core'; import {RouteParams} from 'angular2/router'; import {Hero} from './hero'; @@ -7,11 +7,10 @@ import {HeroService} from './hero.service'; @Component({ selector: 'my-hero-detail', templateUrl: 'app/hero-detail.component.html', - styleUrls: ['app/hero-detail.component.css'], - inputs: ['hero'] + styleUrls: ['app/hero-detail.component.css'] }) export class HeroDetailComponent implements OnInit { - public hero: Hero; + @Input() hero: Hero; constructor(private _heroService: HeroService, private _routeParams: RouteParams) { diff --git a/public/docs/_examples/tutorial/ts/app/hero.ts b/public/docs/_examples/tutorial/ts/app/hero.ts index 34f6058c2f..e94ec6124a 100644 --- a/public/docs/_examples/tutorial/ts/app/hero.ts +++ b/public/docs/_examples/tutorial/ts/app/hero.ts @@ -1,4 +1,4 @@ -export interface Hero { +export class Hero { id: number; name: string; } diff --git a/public/docs/_examples/tutorial/ts/app/heroes.component.css b/public/docs/_examples/tutorial/ts/app/heroes.component.css index d939ab565d..35e45af98d 100644 --- a/public/docs/_examples/tutorial/ts/app/heroes.component.css +++ b/public/docs/_examples/tutorial/ts/app/heroes.component.css @@ -6,7 +6,7 @@ margin: 0 0 2em 0; list-style-type: none; padding: 0; - width: 10em; + width: 15em; } .heroes li { cursor: pointer; diff --git a/public/docs/_examples/tutorial/ts/app/heroes.component.ts b/public/docs/_examples/tutorial/ts/app/heroes.component.ts index 2783981337..86996127a9 100644 --- a/public/docs/_examples/tutorial/ts/app/heroes.component.ts +++ b/public/docs/_examples/tutorial/ts/app/heroes.component.ts @@ -11,8 +11,8 @@ import {Hero} from './hero'; directives: [HeroDetailComponent] }) export class HeroesComponent implements OnInit { - public heroes: Hero[]; - public selectedHero: Hero; + heroes: Hero[]; + selectedHero: Hero; constructor(private _heroService: HeroService, private _router: Router) { } diff --git a/public/docs/_examples/user-input/dart/lib/app_component.dart b/public/docs/_examples/user-input/dart/lib/app_component.dart index 4a2f3fe6ff..d86db43cb0 100644 --- a/public/docs/_examples/user-input/dart/lib/app_component.dart +++ b/public/docs/_examples/user-input/dart/lib/app_component.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; import 'click_me_component.dart'; import 'click_me_component_2.dart'; diff --git a/public/docs/_examples/user-input/dart/lib/click_me_component.dart b/public/docs/_examples/user-input/dart/lib/click_me_component.dart index eaad88dd0c..c1c7e19f93 100644 --- a/public/docs/_examples/user-input/dart/lib/click_me_component.dart +++ b/public/docs/_examples/user-input/dart/lib/click_me_component.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; // #docregion click-me-component @Component( diff --git a/public/docs/_examples/user-input/dart/lib/click_me_component_2.dart b/public/docs/_examples/user-input/dart/lib/click_me_component_2.dart index e96399d943..8047b2280a 100644 --- a/public/docs/_examples/user-input/dart/lib/click_me_component_2.dart +++ b/public/docs/_examples/user-input/dart/lib/click_me_component_2.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; @Component( selector: 'click-me2', diff --git a/public/docs/_examples/user-input/dart/lib/keyup_components.dart b/public/docs/_examples/user-input/dart/lib/keyup_components.dart index e48056a1aa..c38a51e9a3 100644 --- a/public/docs/_examples/user-input/dart/lib/keyup_components.dart +++ b/public/docs/_examples/user-input/dart/lib/keyup_components.dart @@ -2,7 +2,7 @@ // #docregion import 'dart:html'; -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; // #docregion key-up-component-1 @Component( diff --git a/public/docs/_examples/user-input/dart/lib/little_tour_component.dart b/public/docs/_examples/user-input/dart/lib/little_tour_component.dart index ba98f37d68..581689a85e 100644 --- a/public/docs/_examples/user-input/dart/lib/little_tour_component.dart +++ b/public/docs/_examples/user-input/dart/lib/little_tour_component.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; // #docregion little-tour @Component( diff --git a/public/docs/_examples/user-input/dart/lib/loop_back_component.dart b/public/docs/_examples/user-input/dart/lib/loop_back_component.dart index b79f3f5ac4..f2ceb75d11 100644 --- a/public/docs/_examples/user-input/dart/lib/loop_back_component.dart +++ b/public/docs/_examples/user-input/dart/lib/loop_back_component.dart @@ -1,5 +1,5 @@ // #docregion -import 'package:angular2/angular2.dart'; +import 'package:angular2/core.dart'; // #docregion loop-back-component @Component( diff --git a/public/docs/_examples/user-input/dart/pubspec.yaml b/public/docs/_examples/user-input/dart/pubspec.yaml index 4563ea5f93..b800042a03 100644 --- a/public/docs/_examples/user-input/dart/pubspec.yaml +++ b/public/docs/_examples/user-input/dart/pubspec.yaml @@ -5,9 +5,9 @@ version: 0.0.1 environment: sdk: '>=1.13.0 <2.0.0' dependencies: - angular2: 2.0.0-beta.11 + angular2: 2.0.0-beta.13.1 browser: ^0.10.0 - dart_to_js_script_rewriter: ^0.1.0 + dart_to_js_script_rewriter: ^1.0.1 transformers: - angular2: platform_directives: 'package:angular2/common.dart#CORE_DIRECTIVES' diff --git a/public/docs/_examples/user-input/dart/web/main.dart b/public/docs/_examples/user-input/dart/web/main.dart index f74bf40a09..fc77aef43b 100644 --- a/public/docs/_examples/user-input/dart/web/main.dart +++ b/public/docs/_examples/user-input/dart/web/main.dart @@ -1,5 +1,6 @@ // #docregion -import 'package:angular2/bootstrap.dart'; +import 'package:angular2/platform/browser.dart'; + import 'package:user_input/app_component.dart'; main() { diff --git a/public/docs/dart/latest/_data.json b/public/docs/dart/latest/_data.json index 8c221c6385..20395954fe 100644 --- a/public/docs/dart/latest/_data.json +++ b/public/docs/dart/latest/_data.json @@ -3,7 +3,7 @@ "icon": "home", "title": "Angular Docs", "menuTitle": "Docs Home", - "banner": "Angular 2 is currently in Beta." + "banner": "Welcome to angular.io/dart! The current Angular 2 release is beta.14. Consult the Change Log about recent enhancements, fixes, and breaking changes." }, "quickstart": { @@ -35,10 +35,10 @@ "title": "API Preview", "reference": true }, - + "cheatsheet": { "title": "Angular Cheat Sheet", - "intro": "A quick quide to Angular syntax.", + "intro": "A quick guide to Angular syntax.", "reference": true }, @@ -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/dart/latest/cookbook/_data.json b/public/docs/dart/latest/cookbook/_data.json index 71d17069b1..ce8315d497 100644 --- a/public/docs/dart/latest/cookbook/_data.json +++ b/public/docs/dart/latest/cookbook/_data.json @@ -2,18 +2,36 @@ "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" + }, + + "dependency-injection": { + "title": "Dependency Injection", + "intro": "Techniques for Dependency Injection", + "hide": true + }, + + "dynamic-forms": { + "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/dependency-injection.jade b/public/docs/dart/latest/cookbook/dependency-injection.jade new file mode 100644 index 0000000000..f8df2a84a6 --- /dev/null +++ b/public/docs/dart/latest/cookbook/dependency-injection.jade @@ -0,0 +1 @@ +!= partial("../../../_includes/_ts-temp") \ 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/dart/latest/guide/_data.json b/public/docs/dart/latest/guide/_data.json index ad902928f1..fca35dcc06 100644 --- a/public/docs/dart/latest/guide/_data.json +++ b/public/docs/dart/latest/guide/_data.json @@ -52,7 +52,7 @@ "cheatsheet": { "title": "Angular Cheat Sheet", - "intro": "A quick quide to Angular syntax.", + "intro": "A quick guide to Angular syntax.", "nextable": true, "basics": true }, @@ -62,6 +62,11 @@ "intro": "Attribute directives attach behavior to elements." }, + "component-styles": { + "title": "Component Styles", + "intro": "Learn how to apply CSS styles to components." + }, + "hierarchical-dependency-injection": { "title": "Hierarchical Dependency Injectors", "navTitle": "Hierarchical Injectors", diff --git a/public/docs/dart/latest/guide/component-styles.jade b/public/docs/dart/latest/guide/component-styles.jade new file mode 100644 index 0000000000..f8df2a84a6 --- /dev/null +++ b/public/docs/dart/latest/guide/component-styles.jade @@ -0,0 +1 @@ +!= partial("../../../_includes/_ts-temp") \ No newline at end of file diff --git a/public/docs/dart/latest/guide/dependency-injection.jade b/public/docs/dart/latest/guide/dependency-injection.jade index 72fdaa1a49..ee0d41deef 100644 --- a/public/docs/dart/latest/guide/dependency-injection.jade +++ b/public/docs/dart/latest/guide/dependency-injection.jade @@ -1,11 +1,279 @@ include ../_util-fns ++includeShared('{ts}', 'intro') + +:marked + The complete source code for the example app in this chapter is + [in GitHub](https://github.com/angular/angular.io/tree/master/public/docs/_examples/dependency-injection/dart). + ++includeShared('{ts}', 'why-1') ++makeExample('dependency-injection/dart/lib/car/car_no_di.dart', 'car', 'lib/car/car.dart (without DI)') ++includeShared('{ts}', 'why-2') ++makeTabs( + 'dependency-injection/dart/lib/car/car.dart, dependency-injection/dart/lib/car/car_no_di.dart', + 'car-ctor, car-ctor', + 'lib/car/car.dart (excerpt with DI), lib/car/car.dart (excerpt without DI)')(format=".") ++includeShared('{ts}', 'why-3-1') ++includeShared('{ts}', 'why-3-2') +- var stylePattern = { otl: /(new Car.*$)/gm }; ++makeExample('dependency-injection/dart/lib/car/car_creations.dart', 'car-ctor-instantiation', '', stylePattern)(format=".") ++includeShared('{ts}', 'why-4') +.l-sub-section + :marked + The _consumer_ of `Car` has the problem. The consumer must update the car creation code to + something like this: + - var stylePattern = { otl: /(new Car.*$)/gm }; + +makeExample('dependency-injection/dart/lib/car/car_creations.dart', 'car-ctor-instantiation-with-param', '', stylePattern)(format=".") + :marked + The critical point is this: `Car` itself did not have to change. + We'll take care of the consumer's problem soon enough. ++includeShared('{ts}', 'why-6') +- var stylePattern = { otl: /(new Car.*$)/gm }; ++makeExample('dependency-injection/dart/lib/car/car_creations.dart', 'car-ctor-instantiation-with-mocks', '', stylePattern)(format=".") ++includeShared('{ts}', 'why-7') ++makeExample('dependency-injection/dart/lib/car/car_factory.dart', null, 'lib/car/car_factory.dart') ++includeShared('{ts}', 'why-8') ++makeExample('dependency-injection/dart/lib/car/car_injector.dart','injector-call')(format=".") ++includeShared('{ts}', 'why-9') + ++includeShared('{ts}', 'di-1') ++makeTabs( + `dependency-injection/dart/lib/heroes/heroes_component_1.dart, + dependency-injection/dart/lib/heroes/hero_list_component_1.dart, + dependency-injection/dart/lib/heroes/hero.dart, + dependency-injection/dart/lib/heroes/mock_heroes.dart`, + 'v1,,,', + `lib/heroes/heroes_component.dart, + lib/heroes/hero_list_component.dart, + lib/heroes/hero.dart, + lib/heroes/mock_heroes.dart`) ++includeShared('{ts}', 'di-2') ++includeShared('{ts}', 'di-3') ++makeExample('dependency-injection/dart/lib/heroes/hero_service_1.dart',null, 'lib/heroes/hero_service.dart' ) ++includeShared('{ts}', 'di-4') +.l-sub-section + :marked + We aren't even pretending this is a real service. + If we were actually getting data from a remote server, the API would have to be asynchronous, + returning a `Future`. + We'd also have to rewrite the way components consume our service. + This is important in general, but not to our current story. ++includeShared('{ts}', 'di-6') ++includeShared('{ts}', 'di-configure-injector-1') ++makeExample('dependency-injection/dart/web/main.dart', 'bootstrap', 'web/main.dart (excerpt)')(format='.') ++includeShared('{ts}', 'di-configure-injector-2') ++makeExample('dependency-injection/dart/web/main_1.dart', 'bootstrap')(format='.') ++includeShared('{ts}', 'di-configure-injector-3') ++includeShared('{ts}', 'di-register-providers-1') ++makeExample('dependency-injection/dart/lib/heroes/heroes_component_1.dart',null,'lib/heroes/heroes_component.dart') ++includeShared('{ts}', 'di-register-providers-2') ++makeExample('dependency-injection/dart/lib/heroes/heroes_component_1.dart','providers')(format='.') ++includeShared('{ts}', 'di-register-providers-3') ++includeShared('{ts}', 'di-prepare-for-injection-1') ++makeTabs( + `dependency-injection/dart/lib/heroes/hero_list_component_2.dart, + dependency-injection/dart/lib/heroes/hero_list_component_1.dart`, + null, + `lib/heroes/hero_list_component (with DI), + lib/heroes/hero_list_component (without DI)`) +.l-sub-section + :marked + ### Focus on the constructor + + Adding a parameter to the constructor isn't all that's happening here. + +makeExample('dependency-injection/dart/lib/heroes/hero_list_component_2.dart', 'ctor')(format=".") + :marked + The constructor parameter has a type: `HeroService`. + The `HeroListComponent` class is also annotated with `@Component` + (scroll up to confirm that fact). + Also recall that the parent component (`HeroesComponent`) + has `providers` information for `HeroService`. + + The constructor parameter type, the `@Component` annotation, + and the parent's `providers` information combine to tell the + Angular injector to inject an instance of + `HeroService` whenever it creates a new `HeroListComponent`. ++includeShared('{ts}', 'di-create-injector-implicitly-1') ++makeExample('dependency-injection/dart/lib/car/car_injector.dart','injector-create-and-call')(format=".") ++includeShared('{ts}', 'di-create-injector-implicitly-2') ++includeShared('{ts}', 'di-singleton-services') + +// Skip the testing section, for now. +// includeShared('{ts}', 'di-testing-component-1') +// includeShared('{ts}', 'di-testing-component-2') + ++includeShared('{ts}', 'di-service-service-1') ++makeTabs( + `dependency-injection/dart/lib/heroes/hero_service_2.dart, + dependency-injection/dart/lib/heroes/hero_service_1.dart`, + null, + `lib/heroes/hero_service (v.2), + lib/heroes/hero_service (v.1)`) ++includeShared('{ts}', 'di-service-service-2') ++includeShared('{ts}', 'di-injectable-1') +:marked + Forgetting the `@Injectable()` can cause a runtime error: +code-example(format, language="html"). + Cannot find reflection information on <Type> ++includeShared('{ts}', 'di-injectable-2') +.callout.is-critical + header Always include the parentheses + :marked + Always use `@Injectable()`, not just `@Injectable`. + A metadata annotation must be either a reference to a + compile-time constant variable or a call to a constant + constructor such as `Injectable()`. + If we forget the parentheses, the analyzer will complain: + "Annotation creation must have arguments". If we try to run the + app anyway, it won't work, and the console will say + "expression must be a compile-time constant". ++includeShared('{ts}', 'logger-service-1') ++makeExample( + 'dependency-injection/dart/lib/logger_service.dart',null, 'lib/logger_service') +.l-sub-section + :marked + ### Implementing a logger + + Our examples use a simple logger. + A real implementation would probably use the + [logging package](https://pub.dartlang.org/packages/logging). +:marked + We're likely to need the same logger service everywhere in our application, + so we put it in the `lib/` folder, and + we register it in the `providers` array of the metadata for our application root component, `AppComponent`. ++makeExample('dependency-injection/dart/lib/providers_component.dart','providers-logger', 'lib/app_component.dart (excerpt)') ++includeShared('{ts}', 'logger-service-3') ++includeShared('{ts}', 'logger-service-4') ++includeShared('{ts}', 'logger-service-5') ++makeExample('dependency-injection/dart/lib/providers_component.dart','provider-10-ctor')(format='.') ++includeShared('{ts}', 'logger-service-6') ++makeExample('dependency-injection/dart/lib/providers_component.dart','provider-10-logger')(format='.') ++includeShared('{ts}', 'logger-service-7') + ++includeShared('{ts}', 'providers-1') ++makeExample('dependency-injection/dart/lib/providers_component.dart','providers-logger') ++includeShared('{ts}', 'providers-2') ++includeShared('{ts}', 'providers-provide-1') +:marked + ### The *Provider* class ++includeShared('{ts}', 'providers-provide-1-1') ++makeExample('dependency-injection/dart/lib/providers_component.dart','providers-1') ++includeShared('{ts}', 'providers-provide-2') ++makeExample('dependency-injection/dart/lib/providers_component.dart','providers-2') +// includeShared('{ts}', 'providers-provide-3') +// includeShared('{ts}', 'providers-provide-4-1') +// Don't discuss provide function. +:marked + We supply two arguments (or more) to the `Provider` constructor. ++includeShared('{ts}', 'providers-provide-4-2') +:marked + The second is a named parameter, such as `useClass`, + that we can think of as a *recipe* for creating the dependency value. + There are many ways to create dependency values... and many ways to write a recipe. ++includeShared('{ts}', 'providers-alternative-1') ++makeExample('dependency-injection/dart/lib/providers_component.dart','providers-4') +.callout.is-helpful + header Dart difference: Constants in metadata + :marked + In Dart, the value of a metadata annotation must be a compile-time constant. + For that reason, we can't call functions to get values + to use within an annotation. + Instead, we use constant literals or constant constructors. + For example, a TypeScript program might use the + function call `provide(Logger, {useClass: BetterLogger})`, + which is equivalent to the TypeScript code + `new Provider(Logger, {useClass: BetterLogger})`. + A Dart annotation would instead use the constant value `const Provider(Logger, useClass: BetterLogger)`. ++includeShared('{ts}', 'providers-alternative-2') ++makeExample('dependency-injection/dart/lib/providers_component.dart','EvenBetterLogger') ++includeShared('{ts}', 'providers-alternative-3') ++makeExample('dependency-injection/dart/lib/providers_component.dart','providers-5')(format=".") ++includeShared('{ts}', 'providers-aliased-1') ++makeExample('dependency-injection/dart/lib/providers_component.dart','providers-6a')(format=".") ++includeShared('{ts}', 'providers-aliased-2') +- var stylePattern = { otl: /(useExisting.*\))/gm }; ++makeExample('dependency-injection/dart/lib/providers_component.dart','providers-6b','', stylePattern)(format=".") + ++includeShared('{ts}', 'providers-value-1') :marked - We're working on the Dart version of this chapter. - In the meantime, please see these resources: + We can provide objects directly, + instead of asking the injector to create an instance of a class, + by specifying a `useValue` parameter to `Provider`. + + Because Dart annotations must be compile-time constants, + `useValue` is often used with string or list literals. + However, `useValue` works with any constant object. + + To create a class that can provide constant objects, + make sure all its instance variables are `final`, + and give it a `const` constructor: + ++makeExample('dependency-injection/dart/lib/app_config.dart','const-class','lib/app_config.dart (excerpt)')(format='.') + +:marked + Create a constant instance of the class by using `const` instead of `new`: + ++makeExample('dependency-injection/dart/lib/app_config.dart','const-object','lib/app_config.dart (excerpt)')(format='.') + +:marked + Then specify the object using the `useValue` argument to `Provider`: + +- var stylePattern = { otl: /(useValue.*\))/gm }; ++makeExample('dependency-injection/dart/lib/providers_component.dart','providers-9','', stylePattern)(format='.') + +:marked + See more `useValue` examples in the + [Non-class dependencies](#non-class-dependencies) and + [OpaqueToken](#opaquetoken) sections. + ++includeShared('{ts}', 'providers-factory-1') ++makeExample('dependency-injection/dart/lib/heroes/hero_service.dart','internals', 'lib/heroes/hero_service.dart (excerpt)')(format='.') ++includeShared('{ts}', 'providers-factory-2') ++makeExample('dependency-injection/dart/lib/heroes/hero_service_provider.dart','factory', 'lib/heroes/hero_service_provider.dart (excerpt)')(format='.') ++includeShared('{ts}', 'providers-factory-3') ++makeExample('dependency-injection/dart/lib/heroes/hero_service_provider.dart','provider', 'lib/heroes/hero_service_provider.dart (excerpt)')(format='.') ++includeShared('{ts}', 'providers-factory-4') ++includeShared('{ts}', 'providers-factory-5') +- var stylePattern = { otl: /(providers.*),$/gm }; ++makeTabs( + `dependency-injection/dart/lib/heroes/heroes_component.dart, + dependency-injection/dart/lib/heroes/heroes_component_1.dart`, + null, + `lib/heroes/heroes_component (v.3), + lib/heroes/heroes_component (v.2)`, + stylePattern) ++includeShared('{ts}', 'tokens-1') ++makeExample('dependency-injection/dart/lib/injector_component.dart','get-hero-service')(format='.') ++includeShared('{ts}', 'tokens-2') +// [PENDING: How about a better name than ProviderComponent8?] ++makeExample('dependency-injection/dart/lib/providers_component.dart','provider-8-ctor')(format=".") ++includeShared('{ts}', 'tokens-3') +.callout.is-helpful + header Dart difference: Interfaces are valid tokens + :marked + In TypeScript, interfaces don't work as provider tokens. + Dart doesn't have this problem; + every class implicitly defines an interface, + so interface names are just class names. ++includeShared('{ts}', 'tokens-non-class-deps-1') +:marked + We know we can register an object with a [value provider](#value-provider). + But what do we use for the token? ++includeShared('{ts}', 'tokens-opaque-1') ++makeExample('dependency-injection/dart/lib/providers_component.dart','opaque-token')(format='.') ++includeShared('{ts}', 'tokens-opaque-2') ++makeExample('dependency-injection/dart/lib/providers_component.dart','use-opaque-token')(format=".") +:marked + Here's an example of providing configuration information + for an injected class. First define the class: ++makeExample('dependency-injection/dart/lib/providers_component.dart','configurable-logger')(format=".") +:marked + Then inject that class and its configuration information: ++makeExample('dependency-injection/dart/lib/providers_component.dart','providers-7')(format=".") + - * [Dependency Injection](/docs/ts/latest/guide/dependency-injection.html): - The TypeScript version of this chapter ++includeShared('{ts}', 'summary') - * [Dart source code](https://github.com/angular/angular.io/tree/master/public/docs/_examples/dependency-injection/dart): - A preliminary version of the example code that will appear in this chapter ++includeShared('{ts}', 'appendix-explicit-injector-1') ++makeExample('dependency-injection/dart/lib/injector_component.dart', 'injector', 'lib/injector_component.dart') ++includeShared('{ts}', 'appendix-explicit-injector-2') diff --git a/public/docs/dart/latest/guide/displaying-data.jade b/public/docs/dart/latest/guide/displaying-data.jade index b69eb829ef..784cc2ef70 100644 --- a/public/docs/dart/latest/guide/displaying-data.jade +++ b/public/docs/dart/latest/guide/displaying-data.jade @@ -43,7 +43,7 @@ figure.image-display In `main.dart`, importing `app_component.dart` lets us implement part of the app in a different Dart file. The QuickStart version of `main.dart` - imported `angular2.dart`, but we don't need that import here because + imported `core.dart`, but we don't need that import here because this version of `main.dart` is so basic: it only bootstraps the app, and doesn't implement any components or other injectable types. diff --git a/public/docs/dart/latest/quickstart.jade b/public/docs/dart/latest/quickstart.jade index 722ae8cfe3..63511ad106 100644 --- a/public/docs/dart/latest/quickstart.jade +++ b/public/docs/dart/latest/quickstart.jade @@ -41,9 +41,9 @@ p. specify the angular2 and browser packages as dependencies, as well as the angular2 transformer. Angular 2 is still changing, so provide an exact version: - 2.0.0-beta.11. + 2.0.0-beta.13.1. - +makeExample('quickstart/dart/ex1/pubspec.yaml', null, 'pubspec.yaml') + +makeExample('quickstart/dart/pubspec.yaml', 'no-rewriter', 'pubspec.yaml') p. In the same directory, create a web directory, and then @@ -71,7 +71,7 @@ p. p. Paste the following code into web/main.dart: - +makeExample('quickstart/dart/ex1/web/main.dart', null, 'web/main.dart') + +makeExample('quickstart/dart/web/main.dart', null, 'web/main.dart') :marked You've just defined an Angular 2 **component**, @@ -106,8 +106,8 @@ p. consist of more components arising in tree-like fashion from this root. The top lines import two libraries. - *All* Dart files that use Angular APIs import `angular2.dart`. - Only files that call `bootstrap()` import `bootstrap.dart`. + *All* Dart files that use Angular APIs import `core.dart`. + Only files that call `bootstrap()` import `platform/browser.dart`. //- ########################## .l-main-section @@ -119,7 +119,7 @@ p. Create a file named web/index.html that contains the following code: - +makeExample('quickstart/dart/ex1/web/index.html', null, 'web/index.html') + +makeExample('quickstart/dart/web/index.html', null, 'web/index.html') :marked The `` tag in the `` is @@ -170,7 +170,7 @@ p. in both the `dependencies` and `transformers` sections. - var stylePattern = { pnk: /(dart_to_js_script_rewriter.*$)|(- dart_to_js_script_rewriter.*$)/gm, otl: /(dependencies:)|(transformers:)/g }; - +makeExample('quickstart/dart/ex2/pubspec.yaml', null, 'pubspec.yaml', stylePattern) + +makeExample('quickstart/dart/pubspec.yaml', null, 'pubspec.yaml', stylePattern) p. Then compile your Dart code to JavaScript, @@ -194,7 +194,7 @@ p. configure the Angular transformer: - var stylePattern = { otl: /(transformers:)|(- angular2:)|(entry_points.*$)/gm }; - +makeExample('quickstart/dart/ex2/pubspec.yaml', null, 'pubspec.yaml', stylePattern) + +makeExample('quickstart/dart/pubspec.yaml', null, 'pubspec.yaml', stylePattern) p. The entry_points item diff --git a/public/docs/js/latest/_data.json b/public/docs/js/latest/_data.json index 8c221c6385..90342c89f3 100644 --- a/public/docs/js/latest/_data.json +++ b/public/docs/js/latest/_data.json @@ -3,7 +3,7 @@ "icon": "home", "title": "Angular Docs", "menuTitle": "Docs Home", - "banner": "Angular 2 is currently in Beta." + "banner": "Welcome to Angular in JavaScript! The current Angular 2 release is beta.14. Please consult the Change Log about recent enhancements, fixes, and breaking changes." }, "quickstart": { @@ -35,10 +35,10 @@ "title": "API Preview", "reference": true }, - + "cheatsheet": { "title": "Angular Cheat Sheet", - "intro": "A quick quide to Angular syntax.", + "intro": "A quick guide to Angular syntax.", "reference": true }, @@ -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..a2040caccf 100644 --- a/public/docs/js/latest/cookbook/_data.json +++ b/public/docs/js/latest/cookbook/_data.json @@ -2,17 +2,33 @@ "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" + }, + + "dependency-injection": { + "title": "Dependency Injection", + "intro": "Techniques for Dependency Injection" + }, + + "dynamic-forms": { + "title": "Dynamic Form", + "intro": "Render dynamic forms with NgFormModel" + }, + + "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/dependency-injection.jade b/public/docs/js/latest/cookbook/dependency-injection.jade new file mode 100644 index 0000000000..f8df2a84a6 --- /dev/null +++ b/public/docs/js/latest/cookbook/dependency-injection.jade @@ -0,0 +1 @@ +!= partial("../../../_includes/_ts-temp") \ 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 `` - - **Replace** Step #1 with these two scripts: - -+makeExample('testing/ts/unit-tests-4.html', 'import-angular')(format=".") - :marked ## Add another spec file - **Create** an `init-caps-pipe.spec.ts` next to `init-caps-pipes.ts` in `src/app` + **Create** a `my-uppercase.pipe.spec.ts` in `app/`. **Stop and restart the TypeScript compiler** to ensure we compile the new file. - **Add** the following lines of rather obvious Jasmine test code + **Add** the following lines of rather obvious Jasmine test code. -+makeExample('testing/ts/app/init-caps-pipe.spec.ts', 'base-pipe-spec') ++makeExample('testing/ts/app/my-uppercase.pipe.spec.ts', 'base-pipe-spec', 'app/my-uppercase.pipe.spec.ts') :marked Note that each test is short (one line in our case). @@ -95,7 +77,7 @@ code-example(format="" language="html" escape="html"). Open `unit-tests.html`. Find `System.import('app/hero.spec')`. - Hmm. We can’t just add `System.import('app/init-caps-pipe.spec')`. + Hmm. We can’t just add `System.import('app/my-uppercase.pipe.spec')`. The first `System.import` returns a promise as does this second import. We can’t run any of the Jasmine tests until **both imports are finished**. @@ -106,18 +88,108 @@ code-example(format="" language="html" escape="html"). +makeExample('testing/ts/unit-tests-4.html', 'promise-all')(format=".") :marked - Try it. The browser should refresh and show + We have a pattern for adding new tests. + + In future, when we add a new spec, we add another `System.import('app/some.spec')` to + the array argument passed to `Promise.all`. + + Try it. The browser should refresh and show the following in the console: + +code-example(format="" language="html" escape="html"). + GET http://localhost:8080/app/my-uppercase.pipe.js 404 (Not Found) + +:marked + Our test failed, as expected. We're importing something that doesn't exist and our test fails saying that. All is going according to plan. + +:marked + ## The pipe, if you please + + The test is asking for a pipe, and we shall deliver. + + **Create** a `my-uppercase.pipe.ts` in `app/`. + + **Stop and restart the TypeScript compiler** to ensure we compile the new file. + + **Add** a basic pipe that doesn't do anything. We know how to make strings uppercase, but we since we're letting the test take the lead let's wait for it to tell us what's next. Maybe it'll surprise us. + ++makeExample('testing/ts/app/my-uppercase.pipe.1.ts', null, 'app/my-uppercase.pipe.ts') + +:marked + Reload our test page and... + +code-example(format="" language="html" escape="html"). + GET http://localhost:8080/angular2/core 404 (Not Found) + +:marked + ## The Angular library, if you please + Looking back at `unit-tests.html` we realize that we have not loaded the Angular library. + Yet we were able to load and test the application’s `Hero` interface. + + **We were lucky!** The `Hero` interface has no dependence on Angular. + If it had depended on Angular, we’d still be staring at the Jasmine “big-time fail” screen: figure.image-display - img(src='/resources/images/devguide/testing-an-angular-pipe/5-specs-0-failures.png' - style="width:400px;" alt="import promises 5 specs, 0 failures") + img(src='/resources/images/devguide/testing-an-angular-pipe/big-time-fail-screen.png' + alt="Jasmine's' big time fail screen") :marked - We have a pattern for adding new tests. + We are writing an Angular application after all and + we were going to need Angular sooner or later. That time has come. - In future, when we add a new spec, we add another `System.import('app/some.spec')` to - the array argument passed to `Promise.all`. + `MyUppercasePipe` depends on Angular as is clear in the first few lines: + ++makeExample('testing/ts/app/my-uppercase.pipe.ts', 'depends-on-angular')(format=".") + +:marked + **Open** `unit-tests.html` + **Find** the `` comment. + + **Replace** the scripts tags beneath it with the all the needed angular scripts: + ++makeExample('testing/ts/unit-tests-5.html', 'import-angular')(format=".") + +:marked + We should now be ready to see our 3 expectations fail when reloading our test page. + +figure.image-display + img(src='/resources/images/devguide/testing-an-angular-pipe/two-failures.png' alt="2 failed tests") + +:marked + ## Uppercase, if you please + + The first two tests that passed were our old `hero` interface tests, so it makes sense that those passed. Of our three new expectations, one still passed though. + + ``` + MyUppercasePipe + transforms "abc" to "ABC" + transforms "abc def" to "ABC DEF" + leaves "ABC DEF" unchanged + ``` + + Ah but of course! Our simple pipe doesn't transform the input at all, and the third test expected + input to not be changed. + + All we have to do now is actually transform text to uppercase in our pipe. + ++makeExample('testing/ts/app/my-uppercase.pipe.ts', 'uppercase')(format=".") + +:marked + Are we done now? + +figure.image-display + img(src='/resources/images/devguide/testing-an-angular-pipe/zero-failures.png' alt="0 failed tests") + +:marked + The glorious green is back with us again! + + We tried a bit of test driven development and it seems to have guided us to success. + + But it's not always feasible. For instance, sometimes we need to write tests for existing functionality, like what we're about to do with the rest of Tour of Heroes. + + If we are writing new code though, writing tests might just be what we need to help us track our progress and keep the end result in sight at all times. + +:marked ## What’s Next? Now we can test parts of our application that we *load* asynchronously with system.js. diff --git a/public/docs/ts/latest/tutorial/_data.json b/public/docs/ts/latest/tutorial/_data.json index 28d02b2ccb..7af60e1992 100644 --- a/public/docs/ts/latest/tutorial/_data.json +++ b/public/docs/ts/latest/tutorial/_data.json @@ -29,5 +29,10 @@ "title": "Routing", "intro": "We add the Angular Component Router and learn to navigate among the views", "nextable": true + }, + "toh-pt6": { + "title": "Http", + "intro": "We load heroes using http", + "nextable": false } } \ No newline at end of file diff --git a/public/docs/ts/latest/tutorial/toh-pt1.jade b/public/docs/ts/latest/tutorial/toh-pt1.jade index 0cc7b6271c..8c7f75d9d9 100644 --- a/public/docs/ts/latest/tutorial/toh-pt1.jade +++ b/public/docs/ts/latest/tutorial/toh-pt1.jade @@ -66,31 +66,15 @@ code-example(format="" language="bash"). ### 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 an interface. + Let's convert the `hero` from a literal string to a class. - Create a `Hero` interface with `id` and `name` properties. + Create a `Hero` class with `id` and `name` properties. For now put this near the top of the `app.component.ts` file, just below the import statement. -+makeExample('toh-1/ts/app/app.component.ts', 'hero-interface-1', 'app.component.ts (Hero interface)')(format=".") - -.l-sub-section - :marked - #### Interface or Class? - Why a `Hero` interface and not a `Hero` class? - We want a strongly typed `Hero`. We get strong typing with either option. - Our choice depends on how we intend to use the `Hero`. - - If we need a `Hero` that goes beyond simple properties, a `Hero` with logic and behavior, - we must define a class. - If we only need type checking, the interface is sufficient and lighter weight. - - Lighter weight? Transpiling a class to JavaScript produces code. - Transpiling an interface produces — nothing. - If the class does nothing (and there is nothing for a `Hero` class to do right now), - we prefer an interface. ++makeExample('toh-1/ts/app/app.component.ts', 'hero-class-1', 'app.component.ts (Hero class)')(format=".") :marked - Now that we have a `Hero` interface, let’s refactor our component’s `hero` property to be of type `Hero`. + 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/ts-snippets/app.component.snippets.pt1.ts', 'hero-property-1', 'app.component.ts (Hero property)')(format=".") diff --git a/public/docs/ts/latest/tutorial/toh-pt2.jade b/public/docs/ts/latest/tutorial/toh-pt2.jade index c39fe9fed4..b9fd02530a 100644 --- a/public/docs/ts/latest/tutorial/toh-pt2.jade +++ b/public/docs/ts/latest/tutorial/toh-pt2.jade @@ -51,13 +51,13 @@ code-example(format="." language="bash"). +makeExample('toh-2/ts/app/app.component.ts', 'hero-array', 'app.component.ts (Hero array)') :marked - The `HEROES` array is of type `Hero`, the interface defined in part one, + The `HEROES` array is of type `Hero`, the class defined in part one, to create an array of heroes. We aspire to fetch this list of heroes from a web service, but let’s take small steps first and display mock heroes. ### Exposing heroes - Let’s create a public property in `AppComponent` that exposes the heroes for binding. + Let’s create a property in `AppComponent` that exposes the heroes for binding. +makeExample('toh-2/ts-snippets/app.component.snippets.pt2.ts', 'hero-array-1', 'app.component.ts (Hero array property)') diff --git a/public/docs/ts/latest/tutorial/toh-pt3.jade b/public/docs/ts/latest/tutorial/toh-pt3.jade index 7f63a49c6c..fd105d8ddc 100644 --- a/public/docs/ts/latest/tutorial/toh-pt3.jade +++ b/public/docs/ts/latest/tutorial/toh-pt3.jade @@ -73,14 +73,13 @@ code-example(format="." language="bash"). :marked --> :marked - We begin by importing the `Component` function from Angular so that we have it handy when we create - the metadata for our component. - + We begin by importing the `Component` and `Input` decorators from Angular because we're going to need them soon. + We create metadata with the `@Component` decorator where we specify the selector name that identifies this component's element. Then we export the class to make it available to other components. - When we finish here, we'll import it into `AppComponent` and refer to its `` element. + When we finish here, we'll import it into `AppComponent` and create a corresponding `` element. :marked #### Hero Detail Template At the moment, the *Heroes* and *Hero Detail* views are combined in one template in `AppComponent`. @@ -100,18 +99,18 @@ code-example(format="." language="bash"). Let’s add that `hero` property we were talking about to the component class. +makeExample('toh-3/ts/app/hero-detail.component.ts', 'hero') :marked - Uh oh. We declared the `hero` property as type `Hero` but our `Hero` interface is over in the `app.component.ts` file. - We have two components, each in their own file, that need to reference the `Hero` interface. + Uh oh. We declared the `hero` property as type `Hero` but our `Hero` class is over in the `app.component.ts` file. + We have two components, each in their own file, that need to reference the `Hero` class. - We solve the problem by relocating the `Hero` interface from `app.component.ts` to its own `hero.ts` file. + We solve the problem by relocating the `Hero` class from `app.component.ts` to its own `hero.ts` file. -+makeExample('toh-3/ts/app/hero.ts', null, 'hero.ts (Exported Hero interface)')(format=".") ++makeExample('toh-3/ts/app/hero.ts', null, 'hero.ts (Exported Hero class)')(format=".") :marked - We export the `Hero` interface from `hero.ts` because we'll need to reference it in both component files. + We export the `Hero` class from `hero.ts` because we'll need to reference it in both component files. Add the following import statement near the top of both `app.component.ts` and `hero-detail.component.ts`. -+makeExample('toh-3/ts/app/hero-detail.component.ts', 'hero-import', 'hero-detail.component.ts and app.component.ts (Import the Hero interface)') ++makeExample('toh-3/ts/app/hero-detail.component.ts', 'hero-import', 'hero-detail.component.ts and app.component.ts (Import the Hero class)') :marked #### The *hero* property is an ***input*** @@ -137,14 +136,13 @@ code-example(format="."). *source* properties do not. :marked There are a couple of ways we can declare that `hero` is an *input*. - We'll do it by adding an `inputs` array to the `@Component` metadata. -+makeExample('toh-3/ts/app/hero-detail.component.ts', 'inputs') + We'll do it the way we *prefer*, by annotating the `hero` property with the `@Input` decorator that we imported earlier. ++makeExample('toh-3/ts/app/hero-detail.component.ts', 'hero-input')(format='.') .l-sub-section :marked - Learn about the `@Input()` decorator way in the + Learn more about the `@Input()` decorator in the [Attribute Directives](../guide/attribute-directives.html#input) chapter. -:marked .l-main-section :marked diff --git a/public/docs/ts/latest/tutorial/toh-pt4.jade b/public/docs/ts/latest/tutorial/toh-pt4.jade index 8400519f85..69d16d7adf 100644 --- a/public/docs/ts/latest/tutorial/toh-pt4.jade +++ b/public/docs/ts/latest/tutorial/toh-pt4.jade @@ -113,7 +113,7 @@ code-example(format="." language="bash"). We'll move the mock data to its own file. Cut the `HEROES` array from `app.component.ts` and paste it to a new file in the `app` folder named `mock-heroes.ts`. - We copy the `import {Hero} ...` statement as well because the heroes array uses the `Hero` interface. + We copy the `import {Hero} ...` statement as well because the heroes array uses the `Hero` class. +makeExample('toh-4/ts/app/mock-heroes.ts', null, 'mock-heroes.ts (Heroes array)') :marked @@ -384,7 +384,7 @@ code-example(format="." language="html"). Like `getHeroes`, it also returns a promise. But this promise waits 2 seconds before resolving the promise with mock heroes. - Back in the `AppComponent`, swap `_heroService.getHeroesSlowly` for `_heroService.getHeroes` + Back in the `AppComponent`, replace `_heroService.getHeroes` with `_heroService.getHeroesSlowly` and see how the app behaves. .l-main-section diff --git a/public/docs/ts/latest/tutorial/toh-pt6.jade b/public/docs/ts/latest/tutorial/toh-pt6.jade new file mode 100644 index 0000000000..eb16023ee7 --- /dev/null +++ b/public/docs/ts/latest/tutorial/toh-pt6.jade @@ -0,0 +1,233 @@ +include ../_util-fns + +:marked + # Http + + Our application has become a huge success and our stakeholders have already expanded the vision to include integration with a hero api. + + The current solution limits us to a fixed set of heroes, but integration with the api will allow us to load heroes dynamically from a database. We will also be able to add, edit and delete heroes. + + In this chapter we will show how to integrate the http based api with our existing application. +:marked + [Run the live example](/resources/live-examples/toh-6/ts/plnkr.html). + +.l-main-section +:marked + ## Where We Left Off + Before we continue with our Tour of Heroes, let’s verify that we have the following structure after adding our hero service + and hero detail component. If not, we’ll need to go back and follow the previous chapters. + +.filetree + .file angular2-tour-of-heroes + .children + .file app + .children + .file app.component.ts + .file app.component.css + .file dashboard.component.css + .file dashboard.component.html + .file dashboard.component.ts + .file hero.ts + .file hero-detail.component.css + .file hero-detail.component.html + .file hero-detail.component.ts + .file hero.service.ts + .file heroes.component.css + .file heroes.component.html + .file heroes.component.ts + .file main.ts + .file mock-heroes.ts + .file node_modules ... + .file typings ... + .file index.html + .file package.json + .file styles.css + .file tsconfig.json + .file typings.json +:marked + ### Keep the app transpiling and running + Open a terminal/console window and enter the following command to + start the TypeScript compiler, start the server, and watch for changes: + +code-example(format="." language="bash"). + npm start + +:marked + The application runs and updates automatically as we continue to build the Tour of Heroes. + +:marked + ## Heroes and Http + + Let's look back at our `HeroService` implementation in the services chapter. Specifically let's revisit the point we made about using promises when loading heroes. + + Wrapping a simple constant in a promise might have seemed like overkill at the time, but we will show why this was an important first step towards moving to `Http`. + + Let's get started by converting `getHeroes()` to use `Http`. + ++makeExample('toh-6/ts/app/hero.service.ts', 'get-heroes', 'hero.service.ts (getHeroes using Http)')(format=".") + +:marked + ### Http Promise + + In our previous implementation we created a promise ourselves and resolved it immediately. When using `Http` we no longer have to create the promise manually. Instead `Http` will create it for us, but we have to call `toPromise()` to get it. + + In the first `then` we convert the response to a json object by calling `res.json()`. + + Our api follows the convention of returning the result wrapped in a `data` property, but we don't want to expose this to the caller, so we flatten the response in the second `then` by returning `res.data`. + +:marked + ### Error Handling + + At the end we are calling `catch` and passing in an error handler. This is an important step since it allows us to catch any error returned by the api. ++makeExample('toh-6/ts/app/hero.service.ts', 'error-handler', 'hero.service.ts (Error handler)')(format=".") + +:marked + ### Promises are Promises + Even though we made significant internal changes to `getHeroes()`, the public signature did not change. Like before we are returning a promise, so the callers of `getHeroes()` will not need to be updated. + +.l-sub-section + :marked + We want to point out that a promise is not the only way to process http calls. We will encounter other approaches such as Observables in subsequent chapters, but for the purposes of this article we are sticking to promises. + +:marked + ## Add, Edit, Delete + + Our stakeholders are incredibly pleased with the added flexibility from the api integration, but it doesn't stop there. Next we want to add the capability to add, edit and delete heroes. + + In this section we will show how to implement http `post`, `put` and `delete` calls in `HeroService` to meet our new requirements. + +:marked + ### Post + + We are using `post` to add new `Hero` objects to our database. Post requests require a little bit more setup than Get requests, but the format is as follows: + ++makeExample('toh-6/ts/app/hero.service.ts', 'post-hero', 'hero.service.ts (post hero)')(format=".") + +:marked + First we create a header and set the content type to `application/json`. Before posting we have to call `JSON.stringify` to convert the hero object to a string. + + ### Put + + `Put` is used to edit a specific hero, but the structure is very similar to a `post` request. The only difference is that we have to change the url slightly by appending the id of the hero we want to edit. + ++makeExample('toh-6/ts/app/hero.service.ts', 'put-hero', 'hero.service.ts (put hero)')(format=".") + +:marked + ### Delete + `delete` is used to delete heroes and the format is identical to `put` except for the function name. + ++makeExample('toh-6/ts/app/hero.service.ts', 'delete-hero', 'hero.service.ts (delete hero)')(format=".") + +:marked + In all three cases we add a `catch` for error handling. + + After these additions our `HeroService` looks like this: + ++makeExample('toh-6/ts/app/hero.service.ts', null, 'hero.service.ts')(format=".") + +:marked + ## Updating Components + + Loading heroes using `Http` required no changes outside of `HeroService`, but we added a few new features as well. In the following section we will update our components to use our new methods to add, edit and delete heroes. + + ### Add/Edit + We already have `HeroDetailComponent` for viewing details about a specific hero. Add and Edit are natural extensions of the detail view, so we are able to reuse `DetailHeroComponent` with a few tweaks. The original component was created to render existing data, but to add new data we have to initialize the `hero` property to an empty `Hero` object. + ++makeExample('toh-6/ts/app/hero-detail.component.ts', 'ngOnInit', 'hero-detail.component.ts (ngOnInit)')(format=".") + +:marked + In order to differentiate between add and edit we are adding a check to see if an id is passed in the url. If the id is absent we bind `HeroDetailComponent` to an empty `Hero` object. In either case, any edits made through the UI will be bound back to the same `hero` property. + + The next step is to add a save method to `HeroDetailComponent` and call the corresponding save method in `HeroesService`. + ++makeExample('toh-6/ts/app/hero-detail.component.ts', 'save', 'hero-detail.component.ts (save)')(format=".") + +:marked + The same save method is used for both add end edit since `HeroService` will know when to call `post` vs `put` based on the state of the `Hero` object. + + We mentioned earlier that `save()` returns a promise, so when the promise resolves, we call `emit` to notify `HeroesComponent` that we just added or modified a hero. `HeroesComponent` is listening for this notification and will refresh the list of heroes to include our recent updates. + +.l-sub-section + :marked + The `emit` "handshake" between `HeroDetailComponent` and `HeroesComponent` is an example of component to component communication. This is a topic for another day, but we have detailed information in our Component Interaction Cookbook + +:marked + Here is `HeroDetailComponent` with the added save button. + +figure.image-display + img(src='/resources/images/devguide/toh/hero-details-save-button.png' alt="Hero Details With Save Button") + +:marked + ### Delete + + We have added the option to delete hereos from `HeroesComponent`. `HeroService` will delete the hero, but we have to filter out the deleted hero from the list to update the view. + ++makeExample('toh-6/ts/app/heroes.component.ts', 'delete', 'heroes.component.ts (delete)')(format=".") + +:marked + Here is `HeroesComponent` with the delete button. + +figure.image-display + img(src='/resources/images/devguide/toh/heroes-list-delete-button.png' alt="Heroes List With Delete Button") + +:marked + ## Integration with Http + + `Http` is not part of Angular core, but exists as a separate add-on module called `angular2/http`. It ships as a separate bundle, so we have to include the bundle in `index.html`. + ++makeExample('toh-6/ts/index.html', 'http', 'index.html (http)')(format=".") + +:marked + The only other thing we have to do is import `HTTP_PROVIDERS` from `angular2/http` and register it in our root component's provider array. + ### Simulating the api + + Our hero api is not deployed to production yet, but for the purposes of this chapter we have decided to integrate with an in-memory web api simulator. Configuring the simulator requires a few extra steps, but we offer detailed documentation here. Keep in mind, the steps to configure the simulator are not required when integrating with a real http api. + + Since we are integrating with the simulator we no longer need `mock-heroes.ts` to load heroes, so it's safe to delete it. + +:marked + ### Review the App Structure + Let’s verify that we have the following structure after all of our good refactoring in this chapter: + +.filetree + .file angular2-tour-of-heroes + .children + .file app + .children + .file app.component.ts + .file app.component.css + .file dashboard.component.css + .file dashboard.component.html + .file dashboard.component.ts + .file hero.ts + .file hero-detail.component.css + .file hero-detail.component.html + .file hero-detail.component.ts + .file hero.service.ts + .file heroes.component.css + .file heroes.component.html + .file heroes.component.ts + .file main.ts + .file hero-data.ts + .file node_modules ... + .file typings ... + .file index.html + .file package.json + .file styles.css + .file sample.css + .file tsconfig.json + .file typings.json + +:marked + +.l-main-section +:marked + ## Recap + + ### The Road Behind + We travelled a great distance in this chapter. + - We add the necessary dependencies to use Http in our application. + - We refactored HeroService to load heroes from a database. + - We extended HeroService to support post, put and delete calls. + - We updated our components to allow adding, editing and deleting of heroes. + - We configured an in-memory api simulator. diff --git a/public/resources/images/bios/deborah.jpg b/public/resources/images/bios/deborah.jpg new file mode 100644 index 0000000000..2b5a7b3cf2 Binary files /dev/null and b/public/resources/images/bios/deborah.jpg differ diff --git a/public/resources/images/cookbooks/dependency-injection/alex.png b/public/resources/images/cookbooks/dependency-injection/alex.png new file mode 100644 index 0000000000..06a9762024 Binary files /dev/null and b/public/resources/images/cookbooks/dependency-injection/alex.png differ diff --git a/public/resources/images/cookbooks/dependency-injection/alice.png b/public/resources/images/cookbooks/dependency-injection/alice.png new file mode 100644 index 0000000000..48d311b37f Binary files /dev/null and b/public/resources/images/cookbooks/dependency-injection/alice.png differ diff --git a/public/resources/images/cookbooks/dependency-injection/date-logger-entry.png b/public/resources/images/cookbooks/dependency-injection/date-logger-entry.png new file mode 100644 index 0000000000..fe7c9953c3 Binary files /dev/null and b/public/resources/images/cookbooks/dependency-injection/date-logger-entry.png differ diff --git a/public/resources/images/cookbooks/dependency-injection/hero-bio-and-content.png b/public/resources/images/cookbooks/dependency-injection/hero-bio-and-content.png new file mode 100644 index 0000000000..bc6ee5da9a Binary files /dev/null and b/public/resources/images/cookbooks/dependency-injection/hero-bio-and-content.png differ diff --git a/public/resources/images/cookbooks/dependency-injection/hero-bio-contact-no-host.png b/public/resources/images/cookbooks/dependency-injection/hero-bio-contact-no-host.png new file mode 100644 index 0000000000..62211bbae6 Binary files /dev/null and b/public/resources/images/cookbooks/dependency-injection/hero-bio-contact-no-host.png differ diff --git a/public/resources/images/cookbooks/dependency-injection/hero-bios-and-contacts.png b/public/resources/images/cookbooks/dependency-injection/hero-bios-and-contacts.png new file mode 100644 index 0000000000..9b196cbd0b Binary files /dev/null and b/public/resources/images/cookbooks/dependency-injection/hero-bios-and-contacts.png differ diff --git a/public/resources/images/cookbooks/dependency-injection/hero-bios.png b/public/resources/images/cookbooks/dependency-injection/hero-bios.png new file mode 100644 index 0000000000..df3fd2140d Binary files /dev/null and b/public/resources/images/cookbooks/dependency-injection/hero-bios.png differ diff --git a/public/resources/images/cookbooks/dependency-injection/hero-of-month.png b/public/resources/images/cookbooks/dependency-injection/hero-of-month.png new file mode 100644 index 0000000000..f7d485df3e Binary files /dev/null and b/public/resources/images/cookbooks/dependency-injection/hero-of-month.png differ diff --git a/public/resources/images/cookbooks/dependency-injection/highlight.png b/public/resources/images/cookbooks/dependency-injection/highlight.png new file mode 100644 index 0000000000..e3dced717c Binary files /dev/null and b/public/resources/images/cookbooks/dependency-injection/highlight.png differ diff --git a/public/resources/images/cookbooks/dependency-injection/logged-in-user.png b/public/resources/images/cookbooks/dependency-injection/logged-in-user.png new file mode 100644 index 0000000000..4a43da33c9 Binary files /dev/null and b/public/resources/images/cookbooks/dependency-injection/logged-in-user.png differ diff --git a/public/resources/images/cookbooks/dependency-injection/minimal-logger-intellisense.png b/public/resources/images/cookbooks/dependency-injection/minimal-logger-intellisense.png new file mode 100644 index 0000000000..1f02db8d76 Binary files /dev/null and b/public/resources/images/cookbooks/dependency-injection/minimal-logger-intellisense.png differ diff --git a/public/resources/images/cookbooks/dependency-injection/sorted-heroes.png b/public/resources/images/cookbooks/dependency-injection/sorted-heroes.png new file mode 100644 index 0000000000..6adfeae498 Binary files /dev/null and b/public/resources/images/cookbooks/dependency-injection/sorted-heroes.png differ diff --git a/public/resources/images/devguide/testing-an-angular-pipe/big-time-fail-screen.png b/public/resources/images/devguide/testing-an-angular-pipe/big-time-fail-screen.png index 65f51f051e..f78f1efc05 100644 Binary files a/public/resources/images/devguide/testing-an-angular-pipe/big-time-fail-screen.png and b/public/resources/images/devguide/testing-an-angular-pipe/big-time-fail-screen.png differ diff --git a/public/resources/images/devguide/testing-an-angular-pipe/two-failures.png b/public/resources/images/devguide/testing-an-angular-pipe/two-failures.png new file mode 100644 index 0000000000..e21b8e7e78 Binary files /dev/null and b/public/resources/images/devguide/testing-an-angular-pipe/two-failures.png differ diff --git a/public/resources/images/devguide/testing-an-angular-pipe/zero-failures.png b/public/resources/images/devguide/testing-an-angular-pipe/zero-failures.png new file mode 100644 index 0000000000..e7bb6a475c Binary files /dev/null and b/public/resources/images/devguide/testing-an-angular-pipe/zero-failures.png differ diff --git a/public/resources/images/devguide/toh/hero-details-save-button.png b/public/resources/images/devguide/toh/hero-details-save-button.png new file mode 100644 index 0000000000..91c201a310 Binary files /dev/null and b/public/resources/images/devguide/toh/hero-details-save-button.png differ diff --git a/public/resources/images/devguide/toh/heroes-list-delete-button.png b/public/resources/images/devguide/toh/heroes-list-delete-button.png new file mode 100644 index 0000000000..da87a20e4a Binary files /dev/null and b/public/resources/images/devguide/toh/heroes-list-delete-button.png differ diff --git a/public/resources/images/devguide/toh/nav-diagram.png b/public/resources/images/devguide/toh/nav-diagram.png index ed202b20ef..f9d634eafa 100644 Binary files a/public/resources/images/devguide/toh/nav-diagram.png and b/public/resources/images/devguide/toh/nav-diagram.png differ diff --git a/tools/api-builder/angular.io-package/index.js b/tools/api-builder/angular.io-package/index.js index c060562743..827d31a22c 100644 --- a/tools/api-builder/angular.io-package/index.js +++ b/tools/api-builder/angular.io-package/index.js @@ -34,8 +34,8 @@ module.exports = new Package('angular.io', [basePackage, targetPackage, cheatshe }; }) -.config(function(parseTagsProcessor) { - parseTagsProcessor.tagDefinitions.push({ name: 'internal', transforms: function() { return true; } }); +.config(function(parseTagsProcessor, getInjectables) { + parseTagsProcessor.tagDefinitions = parseTagsProcessor.tagDefinitions.concat(getInjectables(require('./tag-defs'))); }) .config(function(readTypeScriptModules, writeFilesProcessor, readFilesProcessor) { @@ -139,5 +139,4 @@ module.exports = new Package('angular.io', [basePackage, targetPackage, cheatshe 'IMPLEMENTS', 'ABSTRACT' ]; -}) - +}); diff --git a/tools/api-builder/angular.io-package/tag-defs/deprecated.js b/tools/api-builder/angular.io-package/tag-defs/deprecated.js new file mode 100644 index 0000000000..ba45af3e97 --- /dev/null +++ b/tools/api-builder/angular.io-package/tag-defs/deprecated.js @@ -0,0 +1,5 @@ +module.exports = function() { + return { + name: 'deprecated' + }; +}; diff --git a/tools/api-builder/angular.io-package/tag-defs/howToUse.js b/tools/api-builder/angular.io-package/tag-defs/howToUse.js new file mode 100644 index 0000000000..21d4378a14 --- /dev/null +++ b/tools/api-builder/angular.io-package/tag-defs/howToUse.js @@ -0,0 +1,5 @@ +module.exports = function() { + return { + name: 'howToUse' + }; +}; diff --git a/tools/api-builder/angular.io-package/tag-defs/index.js b/tools/api-builder/angular.io-package/tag-defs/index.js new file mode 100644 index 0000000000..3b1891e8d3 --- /dev/null +++ b/tools/api-builder/angular.io-package/tag-defs/index.js @@ -0,0 +1,6 @@ +module.exports = [ + require('./deprecated'), + require('./howToUse'), + require('./whatItIs'), + require('./internal') +]; diff --git a/tools/api-builder/angular.io-package/tag-defs/internal.js b/tools/api-builder/angular.io-package/tag-defs/internal.js new file mode 100644 index 0000000000..aac449ccf7 --- /dev/null +++ b/tools/api-builder/angular.io-package/tag-defs/internal.js @@ -0,0 +1,8 @@ +module.exports = function() { + return { + name: 'internal', + transforms: function() { + return true; + } + } +}; diff --git a/tools/api-builder/angular.io-package/tag-defs/whatItIs.js b/tools/api-builder/angular.io-package/tag-defs/whatItIs.js new file mode 100644 index 0000000000..e0308b310d --- /dev/null +++ b/tools/api-builder/angular.io-package/tag-defs/whatItIs.js @@ -0,0 +1,5 @@ +module.exports = function() { + return { + name: 'whatItIs' + }; +}; diff --git a/tools/api-builder/angular.io-package/templates/class.template.html b/tools/api-builder/angular.io-package/templates/class.template.html index 1ae71026de..fe03e03449 100644 --- a/tools/api-builder/angular.io-package/templates/class.template.html +++ b/tools/api-builder/angular.io-package/templates/class.template.html @@ -1,3 +1,6 @@ + + + {% include "lib/githubLinks.html" -%} {% include "lib/paramList.html" -%} {% extends 'layout/base.template.html' -%} diff --git a/tools/api-builder/cheatsheet-package/index.js b/tools/api-builder/cheatsheet-package/index.js index 5b30c5e1f7..2fe5844e85 100644 --- a/tools/api-builder/cheatsheet-package/index.js +++ b/tools/api-builder/cheatsheet-package/index.js @@ -1,6 +1,6 @@ var Package = require('dgeni').Package; -module.exports = new Package('cheatsheet', [require('../content-package'), require('../target-package')]) +module.exports = new Package('cheatsheet', [require('../content-package'), require('../target-package'), require('dgeni-packages/git')]) .factory(require('./services/cheatsheetItemParser')) .processor(require('./processors/createCheatsheetDoc')) diff --git a/tools/plunker-builder/indexHtmlTranslator.js b/tools/plunker-builder/indexHtmlTranslator.js index 65789c4ad4..3591c8e47c 100644 --- a/tools/plunker-builder/indexHtmlTranslator.js +++ b/tools/plunker-builder/indexHtmlTranslator.js @@ -40,47 +40,52 @@ var _rxData = [ { pattern: 'script', from: 'node_modules/angular2/bundles/angular2.dev.js', - to: 'https://code.angularjs.org/2.0.0-beta.12/angular2.dev.js' + to: 'https://code.angularjs.org/2.0.0-beta.14/angular2.dev.js' + }, + { + pattern: 'script', + from: 'node_modules/angular2/bundles/angular2-all.umd.dev.js', + to: 'https://code.angularjs.org/2.0.0-beta.14/angular2-all.umd.dev.js' }, { pattern: 'script', from: 'node_modules/angular2/bundles/angular2-all.umd.js', - to: 'https://code.angularjs.org/2.0.0-beta.12/angular2-all.umd.dev.js' - }, + to: 'https://code.angularjs.org/2.0.0-beta.14/angular2-all.umd.dev.js' + }, { pattern: 'script', from: 'node_modules/angular2/bundles/angular2-polyfills.js', - to: 'https://code.angularjs.org/2.0.0-beta.12/angular2-polyfills.js' + to: 'https://code.angularjs.org/2.0.0-beta.14/angular2-polyfills.js' }, { pattern: 'script', from: 'node_modules/rxjs/bundles/Rx.js', - to: 'https://code.angularjs.org/2.0.0-beta.12/Rx.js' - }, + to: 'https://code.angularjs.org/2.0.0-beta.14/Rx.js' + }, { pattern: 'script', from: 'node_modules/rxjs/bundles/Rx.umd.js', - to: 'https://code.angularjs.org/2.0.0-beta.12/Rx.umd.js' - }, + to: 'https://code.angularjs.org/2.0.0-beta.14/Rx.umd.js' + }, { pattern: 'script', from: 'node_modules/angular2/bundles/router.dev.js', - to: 'https://code.angularjs.org/2.0.0-beta.12/router.dev.js' + to: 'https://code.angularjs.org/2.0.0-beta.14/router.dev.js' }, { pattern: 'script', from: 'node_modules/angular2/bundles/http.dev.js', - to: 'https://code.angularjs.org/2.0.0-beta.12/http.dev.js' + to: 'https://code.angularjs.org/2.0.0-beta.14/http.dev.js' }, { pattern: 'script', from: 'node_modules/angular2/bundles/testing.dev.js', - to: 'https://code.angularjs.org/2.0.0-beta.12/testing.dev.js' + to: 'https://code.angularjs.org/2.0.0-beta.14/testing.dev.js' }, { pattern: 'script', from: 'node_modules/angular2/es6/dev/src/testing/shims_for_IE.js', - to: 'https://npmcdn.com/angular2@2.0.0-beta.12/es6/dev/src/testing/shims_for_IE.js' + to: 'https://npmcdn.com/angular2@2.0.0-beta.14/es6/dev/src/testing/shims_for_IE.js' }, { pattern: 'script', diff --git a/tools/plunker-builder/plunkerBuilder.js b/tools/plunker-builder/plunkerBuilder.js index cb1c405de9..bf784f1e32 100644 --- a/tools/plunker-builder/plunkerBuilder.js +++ b/tools/plunker-builder/plunkerBuilder.js @@ -107,14 +107,16 @@ function initConfigAndCollectFileNames(configFileName) { } }); // var defaultExcludes = [ '!**/node_modules/**','!**/typings/**','!**/tsconfig.json', '!**/*plnkr.json', '!**/*plnkr.html', '!**/*plnkr.no-link.html' ]; - var defaultExcludes = [ + var defaultExcludes = [ '!**/typings/**', '!**/typings.json', - '!**/tsconfig.json', - '!**/*plnkr.*', - '!**/package.json', + '!**/tsconfig.json', + '!**/*plnkr.*', + '!**/package.json', '!**/example-config.json', - '!**/*.spec.*' + '!**/*.spec.*', + '!**/tslint.json', + '!**/.editorconfig' ]; Array.prototype.push.apply(gpaths, defaultExcludes); @@ -263,4 +265,4 @@ function escapeHtml(unsafe) { // fs.writeFileSync(outputFn, html, 'utf-8' ); // } // }); -//} \ No newline at end of file +//}