Merge remote-tracking branch 'origin/master'

# Conflicts:
#	public/docs/_examples/quickstart/ts/package.1.json
#	public/docs/ts/latest/guide/_data.json
#	public/docs/ts/latest/guide/architecture.jade
#	public/docs/ts/latest/guide/forms.jade
#	public/docs/ts/latest/guide/style-guide.jade
#	public/docs/ts/latest/guide/upgrade.jade
This commit is contained in:
Zhicheng Wang 2016-10-01 17:18:44 +08:00
commit dca47cbb1a
262 changed files with 3436 additions and 1810 deletions

View File

@ -295,14 +295,16 @@ function runE2eTsTests(appDir, outputFile) {
try {
var exampleConfig = fs.readJsonSync(`${appDir}/${_exampleConfigFilename}`);
} catch (e) {
exampleConfig = {
build: 'tsc',
run: 'http-server:e2e'
};
exampleConfig = {};
}
var appBuildSpawnInfo = spawnExt('npm', ['run', exampleConfig.build], { cwd: appDir });
var appRunSpawnInfo = spawnExt('npm', ['run', exampleConfig.run, '--', '-s'], { cwd: appDir });
var config = {
build: exampleConfig.build || 'tsc',
run: exampleConfig.run || 'http-server:e2e'
};
var appBuildSpawnInfo = spawnExt('npm', ['run', config.build], { cwd: appDir });
var appRunSpawnInfo = spawnExt('npm', ['run', config.run, '--', '-s'], { cwd: appDir });
return runProtractor(appBuildSpawnInfo.promise, appDir, appRunSpawnInfo, outputFile);
}
@ -1265,7 +1267,7 @@ function apiExamplesWatch(postShredAction) {
}
function devGuideExamplesWatch(shredOptions, postShredAction, focus) {
var watchPattern = focus ? '**/' + focus + '/**/*.*' : '**/*.*';
var watchPattern = focus ? '**/{' + focus + ',cb-' + focus+ '}/**/*.*' : '**/*.*';
var includePattern = path.join(shredOptions.examplesDir, watchPattern);
// removed this version because gulp.watch has the same glob issue that dgeni has.
// var excludePattern = '!' + path.join(shredOptions.examplesDir, '**/node_modules/**/*.*');

View File

@ -3,9 +3,9 @@ name: developer_guide_intro
description: Developer Guide Intro
version: 0.0.1
environment:
sdk: '>=1.13.0 <2.0.0'
sdk: '>=1.19.0 <2.0.0'
dependencies:
angular2: 2.0.0-beta.21
angular2: 2.0.0-beta.22
browser: ^0.10.0
dart_to_js_script_rewriter: ^1.0.1
transformers:

View File

@ -3,9 +3,9 @@ name: attribute_directives
description: Attribute directives example
version: 0.0.1
environment:
sdk: '>=1.13.0 <2.0.0'
sdk: '>=1.19.0 <2.0.0'
dependencies:
angular2: 2.0.0-beta.21
angular2: 2.0.0-beta.22
browser: ^0.10.0
dart_to_js_script_rewriter: ^1.0.1
transformers:

View File

@ -0,0 +1,13 @@
/// <reference path='../_protractor/e2e.d.ts' />
'use strict';
describe('i18n E2E Tests', () => {
beforeEach(function () {
browser.get('');
});
it('should display i18n translated welcome: Bonjour i18n!', function () {
expect(element(by.css('h1')).getText()).toEqual('Bonjour i18n!');
});
});

View File

@ -0,0 +1,6 @@
**/*.ngfactory.ts
**/*.metadata.json
**/messages.xlf
dist
!app/tsconfig.json
!rollup.js

View File

@ -0,0 +1,11 @@
<!--#docregion greeting-->
<h1>Hello i18n!</h1>
<!--#enddocregion greeting-->
<!--#docregion i18n-attribute-->
<h1 i18n>Hello i18n!</h1>
<!--#enddocregion i18n-attribute-->
<!--#docregion i18n-attribute-desc-->
<h1 i18n="An introduction header for this sample">Hello i18n!</h1>
<!--#enddocregion i18n-attribute-desc-->

View File

@ -0,0 +1,4 @@
<!--#docregion-->
<!--#docregion i18n-attribute-meaning-->
<h1 i18n="User welcome|An introduction header for this sample">Hello i18n!</h1>
<!--#enddocregion i18n-attribute-meaning-->

View File

@ -0,0 +1,10 @@
// #docregion
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'my-app',
templateUrl: 'app.component.html'
})
export class AppComponent { }

View File

@ -0,0 +1,13 @@
// #docregion
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
@NgModule({
imports: [ BrowserModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }

View File

@ -0,0 +1,33 @@
// #docregion
import { TRANSLATIONS, TRANSLATIONS_FORMAT, LOCALE_ID } from '@angular/core';
export function getTranslationProviders(): Promise<Object[]> {
// Get the locale id from the global
const locale = document['locale'] as string;
// return no providers if fail to get translation file for locale
const noProviders: Object[] = [];
// No locale or English: no translation providers
if (!locale || locale === 'en') {
return Promise.resolve(noProviders);
}
// Ex: 'i18n/fr/messages.fr.xlf`
const translationFile = `./i18n/${locale}/messages.${locale}.xlf`;
return getTranslationsWithSystemJs(translationFile)
.then( (translations: string ) => [
{ provide: TRANSLATIONS, useValue: translations },
{ provide: TRANSLATIONS_FORMAT, useValue: 'xlf' },
{ provide: LOCALE_ID, useValue: locale }
])
.catch(() => noProviders); // ignore if file not found
}
declare var System: any;
function getTranslationsWithSystemJs(file: string) {
return System.import(file + '!text'); // relies on text plugin
}

View File

@ -0,0 +1,6 @@
// #docregion
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';
platformBrowserDynamic().bootstrapModule(AppModule);

View File

@ -0,0 +1,10 @@
// #docregion
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { getTranslationProviders } from './i18n-providers';
import { AppModule } from './app.module';
getTranslationProviders().then(providers => {
const options = { providers };
platformBrowserDynamic().bootstrapModule(AppModule, options);
});

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="ng2.template">
<body>
<trans-unit id="af2ccf4b5dba59616e92cf1531505af02da8f6d2" datatype="html">
<source>Hello i18n!</source>
<target>Bonjour i18n!</target>
<note priority="1" from="description">An introduction header for this sample</note>
<note priority="1" from="meaning">User welcome</note>
</trans-unit>
</body>
</file>
</xliff>

View File

@ -0,0 +1,17 @@
<!-- The `messages.fr.xlf` after translation for documentation purposes -->
<!-- #docregion -->
<?xml version="1.0" encoding="UTF-8" ?>
<xliff version="1.2" xmlns="urn:oasis:names:tc:xliff:document:1.2">
<file source-language="en" datatype="plaintext" original="ng2.template">
<body>
<!-- #docregion trans-unit -->
<trans-unit id="af2ccf4b5dba59616e92cf1531505af02da8f6d2" datatype="html">
<source>Hello i18n!</source>
<target>Bonjour i18n!</target>
<note priority="1" from="description">An introduction header for this sample</note>
<note priority="1" from="meaning">User welcome</note>
</trans-unit>
<!-- #enddocregion trans-unit -->
</body>
</file>
</xliff>

View File

@ -0,0 +1,7 @@
<!-- #docregion -->
<trans-unit id="af2ccf4b5dba59616e92cf1531505af02da8f6d2" datatype="html">
<source>Hello i18n!</source>
<target/>
<note priority="1" from="description">An introduction header for this sample</note>
<note priority="1" from="meaning">User welcome</note>
</trans-unit>

View File

@ -0,0 +1,39 @@
<!DOCTYPE html>
<!-- #docregion -->
<html>
<head>
<title>Angular i18n example</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">
<script src="node_modules/core-js/client/shim.min.js"></script>
<script src="node_modules/zone.js/dist/zone.js"></script>
<script src="node_modules/reflect-metadata/Reflect.js"></script>
<script src="node_modules/systemjs/dist/system.src.js"></script>
<script src="systemjs.config.js"></script>
<!-- #docregion i18n -->
<script>
// Get the locale id somehow
document.locale = 'fr';
// Map to the text plugin
System.config({
map: {
text: 'systemjs-text-plugin.js'
}
});
// Launch the app
System.import('app').catch(function(err){ console.error(err); });
</script>
<!-- #enddocregion i18n -->
</head>
<body>
<my-app>Loading...</my-app>
</body>
</html>

View File

@ -0,0 +1,17 @@
{
"description": "i18n",
"files": [
"app/**/*.css",
"app/**/*.html",
"app/**/*.ts",
"i18n/messages.xlf",
"i18n/fr/messages.fr.xlf",
"!**/*.[1].*",
"styles.css",
"systemjs-text-plugin.js",
"index.html"
],
"tags": ["i18n"]
}

View File

@ -0,0 +1,14 @@
// #docregion
/*
SystemJS Text plugin from
https://github.com/systemjs/plugin-text/blob/master/text.js
*/
exports.translate = function(load) {
if (this.builder && this.transpiler) {
load.metadata.format = 'esm';
return 'exp' + 'ort var __useDefault = true; exp' + 'ort default ' + JSON.stringify(load.source) + ';';
}
load.metadata.format = 'amd';
return 'def' + 'ine(function() {\nreturn ' + JSON.stringify(load.source) + ';\n});';
}

View File

@ -3,9 +3,9 @@ name: component_styles
description: Component Styles example
version: 0.0.1
environment:
sdk: '>=1.13.0 <2.0.0'
sdk: '>=1.19.0 <2.0.0'
dependencies:
angular2: 2.0.0-beta.21
angular2: 2.0.0-beta.22
browser: ^0.10.0
dart_to_js_script_rewriter: ^1.0.1
transformers:

View File

@ -3,9 +3,9 @@ name: dependency_injection
description: Dependency injection sample
version: 0.0.1
environment:
sdk: '>=1.13.0 <2.0.0'
sdk: '>=1.19.0 <2.0.0'
dependencies:
angular2: 2.0.0-beta.21
angular2: 2.0.0-beta.22
browser: ^0.10.0
dart_to_js_script_rewriter: ^1.0.1
transformers:

View File

@ -3,9 +3,9 @@ name: displaying_data
description: Displaying Data
version: 0.0.1
environment:
sdk: '>=1.13.0 <2.0.0'
sdk: '>=1.19.0 <2.0.0'
dependencies:
angular2: 2.0.0-beta.21
angular2: 2.0.0-beta.22
browser: ^0.10.0
dart_to_js_script_rewriter: ^1.0.1
transformers:

View File

@ -3,9 +3,9 @@ name: hero_form
description: Form example
version: 0.0.1
environment:
sdk: '>=1.13.0 <2.0.0'
sdk: '>=1.19.0 <2.0.0'
dependencies:
angular2: 2.0.0-beta.21
angular2: 2.0.0-beta.22
browser: ^0.10.0
dart_to_js_script_rewriter: ^1.0.1
transformers:

View File

@ -3,9 +3,9 @@ name: 'hierarchical_di'
description: Hierarchical dependency injection example
version: 0.0.1
environment:
sdk: '>=1.13.0 <2.0.0'
sdk: '>=1.19.0 <2.0.0'
dependencies:
angular2: 2.0.0-beta.21
angular2: 2.0.0-beta.22
browser: ^0.10.0
dart_to_js_script_rewriter: ^1.0.1
transformers:

View File

@ -3,9 +3,9 @@ name: lifecycle_hooks
description: Lifecycle Hooks
version: 0.0.1
environment:
sdk: '>=1.13.0 <2.0.0'
sdk: '>=1.19.0 <2.0.0'
dependencies:
angular2: 2.0.0-beta.21
angular2: 2.0.0-beta.22
browser: ^0.10.0
dart_to_js_script_rewriter: ^1.0.1
transformers:

View File

@ -20,41 +20,43 @@
"test:webpack": "karma start karma.webpack.conf.js",
"build:webpack": "rimraf dist && webpack --config config/webpack.prod.js --bail",
"build:cli": "ng build",
"build:aot": "ngc -p tsconfig-aot.json && rollup -c rollup.js"
"build:aot": "ngc -p tsconfig-aot.json && rollup -c rollup.js",
"i18n": "ng-xi18n"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@angular/common": "2.0.0",
"@angular/compiler": "2.0.0",
"@angular/compiler-cli": "0.6.2",
"@angular/core": "2.0.0",
"@angular/forms": "2.0.0",
"@angular/http": "2.0.0",
"@angular/platform-browser": "2.0.0",
"@angular/platform-browser-dynamic": "2.0.0",
"@angular/platform-server": "2.0.0",
"@angular/router": "3.0.0",
"@angular/upgrade": "2.0.0",
"angular-in-memory-web-api": "~0.1.0",
"bootstrap": "^3.3.6",
"@angular/common": "~2.0.1",
"@angular/compiler": "~2.0.1",
"@angular/compiler-cli": "~0.6.3",
"@angular/core": "~2.0.1",
"@angular/forms": "~2.0.1",
"@angular/http": "~2.0.1",
"@angular/platform-browser": "~2.0.1",
"@angular/platform-browser-dynamic": "~2.0.1",
"@angular/platform-server": "~2.0.1",
"@angular/router": "~3.0.1",
"@angular/upgrade": "~2.0.1",
"angular-in-memory-web-api": "~0.1.1",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.3",
"rollup": "^0.34.13",
"reflect-metadata": "^0.1.8",
"rollup": "^0.36.0",
"rollup-plugin-node-resolve": "^2.0.0",
"rollup-plugin-uglify": "^1.0.1",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.38",
"zone.js": "^0.6.23"
"systemjs": "0.19.39",
"zone.js": "^0.6.25"
},
"devDependencies": {
"angular-cli": "^1.0.0-beta.5",
"angular2-template-loader": "^0.4.0",
"awesome-typescript-loader": "^2.2.4",
"canonical-path": "0.0.2",
"concurrently": "^2.2.0",
"css-loader": "^0.23.1",
"concurrently": "^3.0.0",
"css-loader": "^0.25.0",
"extract-text-webpack-plugin": "^1.0.1",
"file-loader": "^0.8.5",
"html-loader": "^0.4.3",
@ -71,19 +73,19 @@
"karma-sourcemap-loader": "^0.3.7",
"karma-webpack": "^1.8.0",
"lite-server": "^2.2.2",
"lodash": "^4.13.1",
"lodash": "^4.16.2",
"null-loader": "^0.1.1",
"phantomjs-prebuilt": "^2.1.7",
"protractor": "^3.3.0",
"raw-loader": "^0.5.1",
"rimraf": "^2.5.2",
"rimraf": "^2.5.4",
"rollup-plugin-commonjs": "^4.1.0",
"style-loader": "^0.13.1",
"ts-loader": "^0.8.2",
"ts-node": "^1.3.0",
"tslint": "^3.15.1",
"typescript": "^2.0.2",
"typings": "^1.3.2",
"typescript": "^2.0.3",
"typings": "^1.4.0",
"webpack": "^1.13.0",
"webpack-dev-server": "^1.14.1",
"webpack-merge": "^0.14.0"

View File

@ -3,9 +3,9 @@ name: pipe_examples
description: Pipes Example
version: 0.0.1
environment:
sdk: '>=1.13.0 <2.0.0'
sdk: '>=1.19.0 <2.0.0'
dependencies:
angular2: 2.0.0-beta.21
angular2: 2.0.0-beta.22
browser: ^0.10.0
dart_to_js_script_rewriter: ^1.0.1
transformers:

View File

@ -5,7 +5,7 @@ import 'package:angular2/core.dart';
// #docregion metadata
@Component(
selector: 'my-app',
template: '<h1>My First Angular 2 App</h1>')
template: '<h1>My First Angular App</h1>')
// #enddocregion metadata
// #docregion class
class AppComponent {}

View File

@ -3,9 +3,9 @@ name: angular2_quickstart
description: QuickStart
version: 0.0.1
environment:
sdk: '>=1.13.0 <2.0.0'
sdk: '>=1.19.0 <2.0.0'
dependencies:
angular2: 2.0.0-beta.21
angular2: 2.0.0-beta.22
browser: ^0.10.0
dart_to_js_script_rewriter: ^1.0.1
transformers:

View File

@ -2,7 +2,7 @@
"name": "angular-quickstart",
"version": "1.0.0",
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
"lite": "lite-server",
"postinstall": "typings install",
"tsc": "tsc",
@ -11,29 +11,28 @@
},
"license": "ISC",
"dependencies": {
"@angular/common": "2.0.0",
"@angular/compiler": "2.0.0",
"@angular/core": "2.0.0",
"@angular/forms": "2.0.0",
"@angular/http": "2.0.0",
"@angular/platform-browser": "2.0.0",
"@angular/platform-browser-dynamic": "2.0.0",
"@angular/router": "3.0.0",
"@angular/upgrade": "2.0.0",
"@angular/common": "~2.0.1",
"@angular/compiler": "~2.0.1",
"@angular/core": "~2.0.1",
"@angular/forms": "~2.0.1",
"@angular/http": "~2.0.1",
"@angular/platform-browser": "~2.0.1",
"@angular/platform-browser-dynamic": "~2.0.1",
"@angular/router": "~3.0.1",
"@angular/upgrade": "~2.0.1",
"angular-in-memory-web-api": "~0.1.1",
"bootstrap": "^3.3.7",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.3",
"reflect-metadata": "^0.1.8",
"rxjs": "5.0.0-beta.12",
"systemjs": "0.19.27",
"zone.js": "^0.6.23",
"angular-in-memory-web-api": "0.1.3",
"bootstrap": "^3.3.6"
"systemjs": "0.19.39",
"zone.js": "^0.6.25"
},
"devDependencies": {
"concurrently": "^2.2.0",
"concurrently": "^3.0.0",
"lite-server": "^2.2.2",
"typescript": "^2.0.2",
"typings":"^1.3.2"
"typescript": "^2.0.3",
"typings":"^1.4.0"
}
}

View File

@ -3,9 +3,9 @@ name: server_communication
description: Server Communication
version: 0.0.1
environment:
sdk: '>=1.13.0 <2.0.0'
sdk: '>=1.19.0 <2.0.0'
dependencies:
angular2: 2.0.0-beta.21
angular2: 2.0.0-beta.22
browser: ^0.10.0
dart_to_js_script_rewriter: ^1.0.1
http: ^0.11.3+3

View File

@ -2,7 +2,7 @@
<!-- #docregion -->
<html>
<head>
<title>Angular 2 Http Demo</title>
<title>Angular Http Demo</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles.css">

View File

@ -3,9 +3,9 @@ name: structural_directives
description: Structural directives example
version: 0.0.1
environment:
sdk: '>=1.13.0 <2.0.0'
sdk: '>=1.19.0 <2.0.0'
dependencies:
angular2: 2.0.0-beta.21
angular2: 2.0.0-beta.22
browser: ^0.10.0
dart_to_js_script_rewriter: ^1.0.1
transformers:

View File

@ -3,7 +3,7 @@
<html>
<head>
<title>Angular 2 Structural Directives</title>
<title>Angular Structural Directives</title>
<link rel="stylesheet" href="styles.css">
<script defer src="main.dart" type="application/dart"></script>
<script defer src="packages/browser/dart.js"></script>

View File

@ -77,13 +77,6 @@ describe('Style Guide', function () {
expect(div.getText()).toBe('This is heroes component');
});
it('04-14', function () {
browser.get('#/04-14');
let h2 = element(by.tagName('sg-app > toh-heroes > div > h2'));
expect(h2.getText()).toBe('My Heroes');
});
it('05-02', function () {
browser.get('#/05-02');

View File

@ -0,0 +1,11 @@
// #docregion
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'toh-app',
template: `
Tour of Heroes
`
})
export class AppComponent { }

View File

@ -1,19 +1,23 @@
// #docplaster
// #docregion
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { HeroesComponent } from './heroes';
@NgModule({
imports: [
BrowserModule,
RouterModule.forChild([{ path: '04-14', component: AppComponent }])
// #enddocregion
RouterModule.forChild([{ path: '02-05', component: AppComponent }])
// #docregion
],
declarations: [
AppComponent,
HeroesComponent
AppComponent
],
exports: [ AppComponent ]
exports: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule {}
export class AppModule { }
// #enddocregion

View File

@ -0,0 +1,8 @@
// #docregion
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app/app.module';
platformBrowserDynamic().bootstrapModule(AppModule)
.then(success => console.log(`Bootstrap success`))
.catch(err => console.error(err));

View File

@ -2,7 +2,8 @@ import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { ValidateDirective } from './shared';
import { InputHighlightDirective,
ValidateDirective } from './shared';
@NgModule({
imports: [
@ -10,6 +11,7 @@ import { ValidateDirective } from './shared';
],
declarations: [
AppComponent,
InputHighlightDirective,
ValidateDirective
],
exports: [ AppComponent ]

View File

@ -1 +1,2 @@
export * from './input-highlight.directive';
export * from './validate.directive';

View File

@ -0,0 +1,10 @@
// #docregion
import { Directive, ElementRef, Renderer } from '@angular/core';
@Directive({ selector: 'input'})
/** Highlight the attached input text element in blue */
export class InputHighlightDirective {
constructor(renderer: Renderer, el: ElementRef) {
renderer.setElementStyle(el.nativeElement, 'backgroundColor', 'powderblue');
}
}

View File

@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { ExceptionService } from './shared';
import { ExceptionService } from './core';
@Component({
selector: 'sg-app',

View File

@ -1,2 +1,2 @@
export * from './shared';
export * from './core';
export * from './app.component';

View File

@ -1,6 +1,6 @@
import { Component } from '@angular/core';
import { heroesUrl, mockHeroes, VILLAINS_URL } from './shared';
import { heroesUrl, mockHeroes, VILLAINS_URL } from './core';
@Component({
selector: 'sg-app',

View File

@ -1,2 +1,2 @@
export * from './shared';
export * from './core';
export * from './app.component';

View File

@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { Hero, HeroCollectorService } from './shared';
import { Hero, HeroCollectorService } from './core';
@Component({
selector: 'sg-app',

View File

@ -1,2 +1,2 @@
export * from './shared';
export * from './core';
export * from './app.component';

View File

@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { ToastService } from './shared';
import { ToastService } from './core';
@Component({
selector: 'sg-app',

View File

@ -8,19 +8,19 @@ import { Injectable } from '@angular/core';
export class ToastService {
message: string;
private _toastCount: number;
private toastCount: number;
hide() {
this._toastCount--;
this._log();
this.toastCount--;
this.log();
}
show() {
this._toastCount++;
this._log();
this.toastCount++;
this.log();
}
private _log() {
private log() {
console.log(this.message);
}
}

View File

@ -1,2 +1,2 @@
export * from './shared';
export * from './core';
export * from './app.component';

View File

@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core';
import { Hero, HeroService } from './heroes';
import { ExceptionService, SpinnerService, ToastService } from './shared';
import { ExceptionService, SpinnerService, ToastService } from './core';
@Component({
moduleId: module.id,

View File

@ -2,7 +2,7 @@
// #docregion example
/* avoid */
import { ExceptionService, SpinnerService, ToastService } from '../../shared';
import { ExceptionService, SpinnerService, ToastService } from '../../core';
import { Http, Response } from '@angular/http';
import { Injectable } from '@angular/core';
import { Hero } from './hero.model';

View File

@ -4,7 +4,7 @@ import { Injectable } from '@angular/core';
import { Http, Response } from '@angular/http';
import { Hero } from './hero.model';
import { ExceptionService, SpinnerService, ToastService } from '../../shared';
import { ExceptionService, SpinnerService, ToastService } from '../../core';
// #enddocregion example
@Injectable()

View File

@ -1,3 +1,3 @@
export * from './heroes';
export * from './shared';
export * from './core';
export * from './app.component';

View File

@ -1,6 +1,6 @@
import { Component, OnInit } from '@angular/core';
import { ToastService } from './toast.service';
import { ToastService } from '../../core';
@Component({
selector: 'toh-toast',

View File

@ -1,3 +1,4 @@
// #docregion
import { Component } from '@angular/core';
@Component({

View File

@ -0,0 +1,28 @@
// #docplaster
// #docregion
// #docregion example
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
// #enddocregion example
import { RouterModule } from '@angular/router';
// #docregion example
import { AppComponent } from './app.component';
import { HeroesComponent } from './heroes/heroes.component';
@NgModule({
imports: [
BrowserModule,
// #enddocregion example
RouterModule.forChild([{ path: '04-08', component: AppComponent }])
// #docregion example
],
declarations: [
AppComponent,
HeroesComponent
],
exports: [ AppComponent ],
entryComponents: [ AppComponent ]
})
export class AppModule {}
// #enddocregion example

View File

@ -0,0 +1 @@
<div>This is heroes component</div>

View File

@ -1,21 +1,21 @@
// #docplaster
// #docregion
// #docregion example
import { Component, OnInit } from '@angular/core';
import { Hero } from './shared';
// #docregion example
import { Logger } from '../shared';
// #enddocregion example
@Component({
// #enddocregion example
moduleId: module.id,
// #docregion example
selector: 'toh-heroes',
templateUrl: 'heroes.component.html',
styleUrls: ['heroes.component.css'],
providers: [Logger]
templateUrl: 'heroes.component.html'
})
export class HeroesComponent implements OnInit {
heroes: Hero[];
selectedHero: Hero;
// #enddocregion example
// #docregion example
constructor() { }
ngOnInit() { }
}
// #enddocregion example

View File

@ -5,5 +5,4 @@ import { Component } from '@angular/core';
selector: 'sg-app',
template: '<toh-heroes></toh-heroes>'
})
export class AppComponent {
}
export class AppComponent { }

View File

@ -1,8 +1,13 @@
// #docplaster
// #docregion
// #docregion example
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RouterModule } from '@angular/router';
// #enddocregion example
import { RouterModule } from '@angular/router';
// #docregion example
import { AppComponent } from './app.component';
import { AppComponent } from './app.component';
import { HeroesComponent } from './heroes/heroes.component';
import { SharedModule } from './shared/shared.module';
@ -10,7 +15,9 @@ import { SharedModule } from './shared/shared.module';
imports: [
BrowserModule,
SharedModule,
// #enddocregion example
RouterModule.forChild([{ path: '04-10', component: AppComponent }])
// #docregion example
],
declarations: [
AppComponent,
@ -20,3 +27,4 @@ import { SharedModule } from './shared/shared.module';
entryComponents: [ AppComponent ]
})
export class AppModule {}
// #enddocregion example

View File

@ -1,26 +0,0 @@
/* tslint:disable:no-unused-variable */
// #docregion
// #docregion example
/* avoid */
import { Component, OnInit } from '@angular/core';
import { CONFIG } from '../shared/config';
import { EntityService } from '../shared/entity.service';
import { ExceptionService } from '../shared/exception.service';
import { FilterTextComponent } from '../shared/filter-text/filter-text.component';
import { InitCapsPipe } from '../shared/init-caps.pipe';
import { SpinnerService } from '../shared/spinner/spinner.service';
import { ToastService } from '../shared/toast/toast.service';
@Component({
selector: 'toh-heroes',
templateUrl: 'app/+heroes/heroes.component.html'
})
export class HeroesComponent implements OnInit {
constructor() { }
ngOnInit() { }
}
// #enddocregion example

View File

@ -1 +1,8 @@
<!--#docregion-->
<div>This is heroes component</div>
<ul>
<li *ngFor="let hero of filteredHeroes">
{{hero.name}}
</li>
</ul>
<toh-filter-text (changed)="filterChanged($event)"></toh-filter-text>

View File

@ -3,29 +3,36 @@
// #docregion example
import { Component, OnInit } from '@angular/core';
import {
CONFIG,
EntityService,
ExceptionService,
SpinnerService,
ToastService
} from '../shared';
import { FilterTextService } from '../shared/filter-text/filter-text.service';
@Component({
// #enddocregion example
moduleId: module.id,
providers: [EntityService, ExceptionService, SpinnerService, ToastService],
// #docregion example
selector: 'toh-heroes',
templateUrl: 'heroes.component.html'
})
export class HeroesComponent implements OnInit {
// #enddocregion example
urls = CONFIG.baseUrls;
// #docregion example
constructor() { }
filteredHeroes: any[] = [];
ngOnInit() { }
constructor(private filterService: FilterTextService) { }
heroes = [
{ id: 1, name: 'Windstorm' },
{ id: 2, name: 'Bombasto' },
{ id: 3, name: 'Magneta' },
{ id: 4, name: 'Tornado' }
];
filterChanged(searchText: string) {
this.filteredHeroes = this.filterService.filter(searchText, ['id', 'name'], this.heroes);
}
ngOnInit() {
this.filteredHeroes = this.heroes;
}
}
// #enddocregion example

View File

@ -1,6 +0,0 @@
export let CONFIG = {
baseUrls: {
heroes: 'api/heroes.json',
villains: 'api/villains.json'
}
};

View File

@ -1,4 +0,0 @@
import { Injectable } from '@angular/core';
@Injectable()
export class EntityService { }

View File

@ -1,4 +0,0 @@
import { Injectable } from '@angular/core';
@Injectable()
export class ExceptionService { }

View File

@ -1,19 +1,27 @@
// #docregion
import { Component, EventEmitter, Output } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'toh-filter-text',
template: '<div>filter</div>'
template: '<input type="text" id="filterText" [(ngModel)]="filter" (keyup)="filterChanged($event)" />'
})
export class FilterTextComponent {
@Output() changed: EventEmitter<string>;
filter: string;
constructor() { }
constructor() {
this.changed = new EventEmitter<string>();
}
clear() {
this.filter = '';
}
filterChanged(event: any) {
event.preventDefault();
console.log(`Filter Changed: ${this.filter}`);
this.changed.emit(this.filter);
}
}

View File

@ -1,11 +1,30 @@
// #docregion
import { Injectable } from '@angular/core';
@Injectable()
export class FilterService {
constructor() { }
export class FilterTextService {
constructor() {
console.log('Created an instance of FilterTextService');
}
filter(data: string, props: Array<string>, originalList: Array<any>) {
let filteredList: any[];
if (data && props && originalList) {
data = data.toLowerCase();
let filtered = originalList.filter(item => {
let match = false;
for (let prop of props) {
if (item[prop].toString().toLowerCase().indexOf(data) > -1) {
match = true;
break;
}
};
return match;
});
filteredList = filtered;
} else {
filteredList = originalList;
}
return filteredList;
}
}

View File

@ -1,3 +0,0 @@
// #docregion
export * from './filter-text.component';
export * from './filter-text.service';

View File

@ -1,12 +0,0 @@
// #docregion
// #docregion example
export * from './config';
export * from './entity.service';
export * from './exception.service';
export * from './filter-text';
export * from './init-caps.pipe';
export * from './modal';
export * from './nav';
export * from './spinner';
export * from './toast';
// #enddocregion example

View File

@ -1,8 +1,7 @@
// #docregion
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({ name: 'initCaps' })
export class InitCapsPipe implements PipeTransform {
transform = (value: string) => value;
}

View File

@ -1,3 +0,0 @@
// #docregion
export * from './modal.component';
export * from './modal.service';

View File

@ -1,14 +0,0 @@
import { Component, OnInit } from '@angular/core';
import { ModalService } from './modal.service';
@Component({
moduleId: module.id,
selector: 'toh-modal-confirm',
template: '<div>modal</div>'
})
export class ModalComponent implements OnInit {
constructor(modalService: ModalService) { }
ngOnInit() { }
}

View File

@ -1,6 +0,0 @@
import { Injectable } from '@angular/core';
@Injectable()
export class ModalService {
activate: (message?: string, title?: string) => Promise<boolean>;
}

View File

@ -1,2 +0,0 @@
// #docregion
export * from './nav.component';

View File

@ -1,17 +0,0 @@
import { Component, OnInit } from '@angular/core';
import { ModalService } from '../';
@Component({
moduleId: module.id,
selector: 'toh-nav',
template: '<div>nav</div>'
})
export class NavComponent implements OnInit {
ngOnInit() { }
constructor(private modalService: ModalService) { }
resetDb() { }
}

View File

@ -1,20 +1,24 @@
// #docregion
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { FilterTextComponent,
InitCapsPipe,
ModalComponent,
NavComponent,
SpinnerComponent } from './';
const declarations = [
FilterTextComponent, InitCapsPipe, ModalComponent,
NavComponent, SpinnerComponent,
];
import { FilterTextComponent } from './filter-text/filter-text.component';
import { FilterTextService } from './filter-text/filter-text.service';
import { InitCapsPipe } from './init-caps.pipe';
@NgModule({
imports: [ BrowserModule ],
declarations: declarations,
exports: declarations
imports: [CommonModule, FormsModule],
declarations: [
FilterTextComponent,
InitCapsPipe
],
providers: [FilterTextService],
exports: [
CommonModule,
FormsModule,
FilterTextComponent,
InitCapsPipe
]
})
export class SharedModule { }

View File

@ -1,3 +0,0 @@
// #docregion
export * from './spinner.component';
export * from './spinner.service';

View File

@ -1,16 +0,0 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { SpinnerService } from './spinner.service';
@Component({
selector: 'toh-spinner',
template: '<div>spinner</div>'
})
export class SpinnerComponent implements OnDestroy, OnInit {
constructor(private spinnerService: SpinnerService) { }
ngOnInit() { }
ngOnDestroy() { }
}

Some files were not shown because too many files have changed in this diff Show More