├── angular ├── ng-tut │ ├── src │ │ ├── assets │ │ │ └── .gitkeep │ │ ├── app │ │ │ ├── app.component.css │ │ │ ├── app.component.html │ │ │ ├── app.component.ts │ │ │ ├── app.module.ts │ │ │ └── app.component.spec.ts │ │ ├── styles.css │ │ ├── environments │ │ │ ├── environment.prod.ts │ │ │ └── environment.ts │ │ ├── favicon.ico │ │ ├── typings.d.ts │ │ ├── tsconfig.app.json │ │ ├── index.html │ │ ├── main.ts │ │ ├── tsconfig.spec.json │ │ ├── test.ts │ │ └── polyfills.ts │ ├── e2e │ │ ├── tsconfig.e2e.json │ │ ├── app.po.ts │ │ └── app.e2e-spec.ts │ ├── .editorconfig │ ├── tsconfig.json │ ├── .gitignore │ ├── protractor.conf.js │ ├── README.md │ ├── .angular-cli.json │ ├── package.json │ ├── karma.conf.js │ └── tslint.json ├── pragmatic │ ├── src │ │ ├── assets │ │ │ └── .gitkeep │ │ ├── app │ │ │ ├── core │ │ │ │ ├── footer │ │ │ │ │ ├── footer.component.scss │ │ │ │ │ ├── footer.component.html │ │ │ │ │ ├── footer.component.ts │ │ │ │ │ └── footer.component.spec.ts │ │ │ │ ├── header │ │ │ │ │ ├── header.component.scss │ │ │ │ │ ├── header.component.html │ │ │ │ │ ├── header.component.spec.ts │ │ │ │ │ └── header.component.ts │ │ │ │ ├── auth-guard.service.spec.ts │ │ │ │ ├── auth-guard.service.ts │ │ │ │ └── core.module.ts │ │ │ ├── new-in-ng4 │ │ │ │ ├── reactive │ │ │ │ │ ├── reactive.component.scss │ │ │ │ │ ├── reactive.component.spec.ts │ │ │ │ │ ├── reactive.component.html │ │ │ │ │ └── reactive.component.ts │ │ │ │ ├── new-in-ng4.module.ts │ │ │ │ └── new-in-ng4-routing.module.ts │ │ │ ├── app.component.ts │ │ │ ├── app.component.html │ │ │ ├── app-routing.module.ts │ │ │ ├── app.component.scss │ │ │ ├── app.module.ts │ │ │ ├── utils │ │ │ │ └── type.ts │ │ │ ├── shared │ │ │ │ └── shared.module.ts │ │ │ ├── domain │ │ │ │ └── entities.interface.ts │ │ │ ├── reducers │ │ │ │ └── auth.reducer.ts │ │ │ ├── app.component.spec.ts │ │ │ └── actions │ │ │ │ └── auth.action.ts │ │ ├── environments │ │ │ ├── environment.prod.ts │ │ │ └── environment.ts │ │ ├── favicon.ico │ │ ├── typings.d.ts │ │ ├── tsconfig.app.json │ │ ├── main.ts │ │ ├── tsconfig.spec.json │ │ ├── index.html │ │ ├── test.ts │ │ ├── styles.scss │ │ └── polyfills.ts │ ├── e2e │ │ ├── tsconfig.e2e.json │ │ ├── app.po.ts │ │ └── app.e2e-spec.ts │ ├── .editorconfig │ ├── tsconfig.json │ ├── .gitignore │ ├── protractor.conf.js │ ├── README.md │ ├── .angular-cli.json │ ├── karma.conf.js │ ├── package.json │ └── tslint.json └── from0to1 │ └── chap01 │ └── hello-angular │ ├── src │ ├── assets │ │ └── .gitkeep │ ├── app │ │ ├── app.component.css │ │ ├── app.component.html │ │ ├── app.component.ts │ │ ├── login │ │ │ ├── login.component.ts │ │ │ └── login.component.spec.ts │ │ ├── app.module.ts │ │ └── app.component.spec.ts │ ├── environments │ │ ├── environment.prod.ts │ │ └── environment.ts │ ├── styles.css │ ├── favicon.ico │ ├── typings.d.ts │ ├── tsconfig.app.json │ ├── index.html │ ├── main.ts │ ├── tsconfig.spec.json │ ├── test.ts │ └── polyfills.ts │ ├── e2e │ ├── tsconfig.e2e.json │ ├── app.po.ts │ └── app.e2e-spec.ts │ ├── .editorconfig │ ├── tsconfig.json │ ├── .gitignore │ ├── protractor.conf.js │ ├── .angular-cli.json │ ├── package.json │ ├── karma.conf.js │ └── tslint.json ├── angular2 ├── ng2-tut │ ├── src │ │ ├── assets │ │ │ ├── .gitkeep │ │ │ └── login_default_bg.jpg │ │ ├── app │ │ │ ├── todo │ │ │ │ ├── todo.component.css │ │ │ │ ├── todo-header │ │ │ │ │ ├── todo-header.component.html │ │ │ │ │ ├── todo-header.component.css │ │ │ │ │ ├── todo-header.component.spec.ts │ │ │ │ │ └── todo-header.component.ts │ │ │ │ ├── todo-item │ │ │ │ │ ├── todo-item.component.html │ │ │ │ │ ├── todo-item.component.ts │ │ │ │ │ ├── todo-item.component.css │ │ │ │ │ └── todo-item.component.spec.ts │ │ │ │ ├── todo-footer │ │ │ │ │ ├── todo-footer.component.ts │ │ │ │ │ ├── todo-footer.component.html │ │ │ │ │ ├── todo-footer.component.spec.ts │ │ │ │ │ └── todo-footer.component.css │ │ │ │ ├── todo.service.spec.ts │ │ │ │ ├── todo.component.html │ │ │ │ ├── todo-list │ │ │ │ │ ├── todo-list.component.css │ │ │ │ │ ├── todo-list.component.html │ │ │ │ │ ├── todo-list.component.spec.ts │ │ │ │ │ └── todo-list.component.ts │ │ │ │ ├── todo-routing.module.ts │ │ │ │ ├── todo.component.spec.ts │ │ │ │ ├── todo.module.ts │ │ │ │ ├── todo.component.ts │ │ │ │ └── todo.service.ts │ │ │ ├── playground │ │ │ │ ├── one │ │ │ │ │ ├── one.component.css │ │ │ │ │ ├── one.component.html │ │ │ │ │ ├── one.component.ts │ │ │ │ │ └── one.component.spec.ts │ │ │ │ ├── two │ │ │ │ │ ├── two.component.css │ │ │ │ │ ├── two.component.html │ │ │ │ │ ├── two.component.ts │ │ │ │ │ └── two.component.spec.ts │ │ │ │ ├── three │ │ │ │ │ ├── three.component.css │ │ │ │ │ ├── three.component.html │ │ │ │ │ ├── three.component.ts │ │ │ │ │ └── three.component.spec.ts │ │ │ │ ├── playground.component.css │ │ │ │ ├── trim-space.pipe.ts │ │ │ │ ├── log-on-click.directive.ts │ │ │ │ ├── form-demo │ │ │ │ │ ├── form-demo.component.ts │ │ │ │ │ ├── form-demo.component.css │ │ │ │ │ ├── form-demo.component.spec.ts │ │ │ │ │ └── form-demo.component.html │ │ │ │ ├── playground.component.spec.ts │ │ │ │ ├── playground.module.ts │ │ │ │ ├── playground-routing.module.ts │ │ │ │ ├── playground.component.html │ │ │ │ └── playground.component.ts │ │ │ ├── index.ts │ │ │ ├── login │ │ │ │ ├── register-dialog.component.css │ │ │ │ ├── login.component.css │ │ │ │ ├── login-routing.module.ts │ │ │ │ ├── bing-image.service.spec.ts │ │ │ │ ├── login.module.ts │ │ │ │ ├── login.component.spec.ts │ │ │ │ ├── register-dialog.component.html │ │ │ │ ├── bing-image.service.ts │ │ │ │ ├── login.component.html │ │ │ │ ├── login.component.ts │ │ │ │ └── register-dialog.component.ts │ │ │ ├── app.component.css │ │ │ ├── domain │ │ │ │ ├── state.ts │ │ │ │ └── entities.ts │ │ │ ├── actions │ │ │ │ ├── auth.action.ts │ │ │ │ └── todo.action.ts │ │ │ ├── shared │ │ │ │ └── shared.module.ts │ │ │ ├── core │ │ │ │ ├── auth.service.spec.ts │ │ │ │ ├── user.service.spec.ts │ │ │ │ ├── auth-guard.service.spec.ts │ │ │ │ ├── auth-guard.service.ts │ │ │ │ ├── core.module.ts │ │ │ │ ├── user.service.ts │ │ │ │ └── auth.service.ts │ │ │ ├── app-routing.module.ts │ │ │ ├── app.module.ts │ │ │ ├── app.component.html │ │ │ ├── app.component.ts │ │ │ ├── app.component.spec.ts │ │ │ ├── data.json │ │ │ └── reducers │ │ │ │ ├── auth.reducer.ts │ │ │ │ └── todo.reducer.ts │ │ ├── environments │ │ │ ├── environment.prod.ts │ │ │ └── environment.ts │ │ ├── favicon.ico │ │ ├── styles.css │ │ ├── typings.d.ts │ │ ├── main.ts │ │ ├── index.html │ │ ├── tsconfig.json │ │ ├── polyfills.ts │ │ ├── test.ts │ │ └── styles.scss │ ├── e2e │ │ ├── app.po.ts │ │ ├── app.e2e-spec.ts │ │ └── tsconfig.json │ ├── .editorconfig │ ├── .gitignore │ ├── protractor.conf.js │ ├── karma.conf.js │ ├── angular-cli.json │ ├── package.json │ └── tslint.json ├── playground │ ├── src │ │ ├── assets │ │ │ └── .gitkeep │ │ ├── app │ │ │ ├── app.component.css │ │ │ ├── index.ts │ │ │ ├── app.component.html │ │ │ ├── app.component.ts │ │ │ ├── app.module.ts │ │ │ └── app.component.spec.ts │ │ ├── environments │ │ │ ├── environment.prod.ts │ │ │ └── environment.ts │ │ ├── styles.css │ │ ├── favicon.ico │ │ ├── typings.d.ts │ │ ├── styles.scss │ │ ├── index.html │ │ ├── main.ts │ │ ├── tsconfig.json │ │ ├── polyfills.ts │ │ └── test.ts │ ├── e2e │ │ ├── app.po.ts │ │ ├── app.e2e-spec.ts │ │ └── tsconfig.json │ ├── .editorconfig │ ├── .gitignore │ ├── protractor.conf.js │ ├── README.md │ ├── karma.conf.js │ ├── angular-cli.json │ ├── package.json │ └── tslint.json └── .vscode │ ├── settings.json │ └── launch.json └── README.md /angular/ng-tut/src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /angular/pragmatic/src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /angular/ng-tut/src/app/app.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /angular2/playground/src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo.component.css: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/src/assets/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/one/one.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/two/two.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/src/app/app.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/core/footer/footer.component.scss: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/core/header/header.component.scss: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/three/three.component.css: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /angular2/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // 将设置放入此文件中以覆盖默认值和用户设置。 2 | { 3 | } -------------------------------------------------------------------------------- /angular/pragmatic/src/app/new-in-ng4/reactive/reactive.component.scss: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /angular/ng-tut/src/app/app.component.html: -------------------------------------------------------------------------------- 1 |

2 | {{title}} 3 |

4 | -------------------------------------------------------------------------------- /angular2/playground/src/app/app.component.css: -------------------------------------------------------------------------------- 1 | .container{ 2 | width: 100px; 3 | } 4 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/three/three.component.html: -------------------------------------------------------------------------------- 1 |

2 | three works! 3 |

4 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/index.ts: -------------------------------------------------------------------------------- 1 | export * from './app.component'; 2 | export * from './app.module'; 3 | -------------------------------------------------------------------------------- /angular2/playground/src/app/index.ts: -------------------------------------------------------------------------------- 1 | export * from './app.component'; 2 | export * from './app.module'; 3 | -------------------------------------------------------------------------------- /angular/ng-tut/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/login/register-dialog.component.css: -------------------------------------------------------------------------------- 1 | .status-bar { 2 | text-align: center; 3 | } 4 | -------------------------------------------------------------------------------- /angular/ng-tut/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /angular/pragmatic/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/src/app/app.component.html: -------------------------------------------------------------------------------- 1 |

2 | {{title}} 3 |

4 | -------------------------------------------------------------------------------- /angular/ng-tut/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wpcfan/awesome-tutorials/HEAD/angular/ng-tut/src/favicon.ico -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/app.component.css: -------------------------------------------------------------------------------- 1 | .content { 2 | padding: 0px; 3 | margin: 0px; 4 | height: 100%; 5 | } 6 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/two/two.component.html: -------------------------------------------------------------------------------- 1 |

2 | two works! 3 |

4 | -------------------------------------------------------------------------------- /angular2/playground/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /angular2/playground/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | 3 | -------------------------------------------------------------------------------- /angular/pragmatic/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wpcfan/awesome-tutorials/HEAD/angular/pragmatic/src/favicon.ico -------------------------------------------------------------------------------- /angular2/ng2-tut/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wpcfan/awesome-tutorials/HEAD/angular2/ng2-tut/src/favicon.ico -------------------------------------------------------------------------------- /angular2/playground/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wpcfan/awesome-tutorials/HEAD/angular2/playground/src/favicon.ico -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/src/environments/environment.prod.ts: -------------------------------------------------------------------------------- 1 | export const environment = { 2 | production: true 3 | }; 4 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/playground.component.css: -------------------------------------------------------------------------------- 1 | .traffic-light{ 2 | width: 100px; 3 | height: 100px; 4 | background-color: black; 5 | } -------------------------------------------------------------------------------- /angular/ng-tut/src/typings.d.ts: -------------------------------------------------------------------------------- 1 | /* SystemJS module definition */ 2 | declare var module: NodeModule; 3 | interface NodeModule { 4 | id: string; 5 | } 6 | -------------------------------------------------------------------------------- /angular/pragmatic/src/typings.d.ts: -------------------------------------------------------------------------------- 1 | /* SystemJS module definition */ 2 | declare var module: NodeModule; 3 | interface NodeModule { 4 | id: string; 5 | } 6 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/assets/login_default_bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wpcfan/awesome-tutorials/HEAD/angular2/ng2-tut/src/assets/login_default_bg.jpg -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/src/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wpcfan/awesome-tutorials/HEAD/angular/from0to1/chap01/hello-angular/src/favicon.ico -------------------------------------------------------------------------------- /angular2/ng2-tut/src/styles.css: -------------------------------------------------------------------------------- 1 | /* You can add global styles to this file, and also import other style files */ 2 | .fill-remaining-space { 3 | flex: 1 1 auto; 4 | } -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/src/typings.d.ts: -------------------------------------------------------------------------------- 1 | /* SystemJS module definition */ 2 | declare var module: NodeModule; 3 | interface NodeModule { 4 | id: string; 5 | } 6 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/typings.d.ts: -------------------------------------------------------------------------------- 1 | // Typings reference file, you can add your own global typings here 2 | // https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html 3 | -------------------------------------------------------------------------------- /angular2/playground/src/typings.d.ts: -------------------------------------------------------------------------------- 1 | // Typings reference file, you can add your own global typings here 2 | // https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html 3 | -------------------------------------------------------------------------------- /angular2/playground/src/app/app.component.html: -------------------------------------------------------------------------------- 1 |
2 |
3 |
4 |
5 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/core/footer/footer.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | © 2017 NotACompany 4 | 5 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/domain/state.ts: -------------------------------------------------------------------------------- 1 | import { Todo, Auth } from './entities'; 2 | 3 | export { Todo, Auth } 4 | 5 | export interface AppState{ 6 | todos: Todo[]; 7 | todoFilter: any; 8 | auth: Auth; 9 | } -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/one/one.component.html: -------------------------------------------------------------------------------- 1 |

Without Pipe: Today is {{ birthday }}

2 |

With Pipe: Today is {{ birthday | date:"MM/dd/yy" }}

3 | 6 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo-header/todo-header.component.html: -------------------------------------------------------------------------------- 1 |
2 | 9 |
10 | -------------------------------------------------------------------------------- /angular/ng-tut/e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types":[ 8 | "jasmine", 9 | "node" 10 | ] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /angular/pragmatic/e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types":[ 8 | "jasmine", 9 | "node" 10 | ] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /angular/ng-tut/e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, element, by } from 'protractor'; 2 | 3 | export class NgTutPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /angular2/ng2-tut/e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, element, by } from 'protractor'; 2 | 3 | export class Ng2TutPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /angular/pragmatic/e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, element, by } from 'protractor'; 2 | 3 | export class PragmaticPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /angular/ng-tut/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'] 7 | }) 8 | export class AppComponent { 9 | title = 'app works!'; 10 | } 11 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.scss'] 7 | }) 8 | export class AppComponent { 9 | title = 'app works!'; 10 | } 11 | -------------------------------------------------------------------------------- /angular2/playground/e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, element, by } from 'protractor'; 2 | 3 | export class PlaygroundPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/e2e/tsconfig.e2e.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/e2e", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "types":[ 8 | "jasmine", 9 | "node" 10 | ] 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /angular/ng-tut/src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "es2015", 6 | "baseUrl": "", 7 | "types": [] 8 | }, 9 | "exclude": [ 10 | "test.ts", 11 | "**/*.spec.ts" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/trim-space.pipe.ts: -------------------------------------------------------------------------------- 1 | import { Pipe, PipeTransform } from '@angular/core'; 2 | @Pipe({ 3 | name: 'trimSpace' 4 | }) 5 | export class TrimSpacePipe implements PipeTransform { 6 | transform(value: any, args: any[]): any { 7 | return value.replace(/ /g, ''); 8 | } 9 | } -------------------------------------------------------------------------------- /angular/pragmatic/src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "es2015", 6 | "baseUrl": "", 7 | "types": [] 8 | }, 9 | "exclude": [ 10 | "test.ts", 11 | "**/*.spec.ts" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/e2e/app.po.ts: -------------------------------------------------------------------------------- 1 | import { browser, element, by } from 'protractor'; 2 | 3 | export class HelloAngularPage { 4 | navigateTo() { 5 | return browser.get('/'); 6 | } 7 | 8 | getParagraphText() { 9 | return element(by.css('app-root h1')).getText(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/login/login.component.css: -------------------------------------------------------------------------------- 1 | .login-container{ 2 | min-height: 100%; 3 | max-height: 100%; 4 | background-size: cover; /* <------ */ 5 | background-repeat: no-repeat; 6 | background-position: center center; 7 | } 8 | .login-form { 9 | padding-top: 50px; 10 | } 11 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/src/tsconfig.app.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/app", 5 | "module": "es2015", 6 | "baseUrl": "", 7 | "types": [] 8 | }, 9 | "exclude": [ 10 | "test.ts", 11 | "**/*.spec.ts" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /angular/ng-tut/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /angular/pragmatic/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /angular2/ng2-tut/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'] 7 | }) 8 | export class AppComponent { 9 | title = 'This is a hello-angular app'; 10 | } 11 | -------------------------------------------------------------------------------- /angular2/playground/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/.editorconfig: -------------------------------------------------------------------------------- 1 | # Editor configuration, see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | indent_style = space 7 | indent_size = 2 8 | insert_final_newline = true 9 | trim_trailing_whitespace = true 10 | 11 | [*.md] 12 | max_line_length = off 13 | trim_trailing_whitespace = false 14 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/actions/auth.action.ts: -------------------------------------------------------------------------------- 1 | export const LOGIN = 'LOGIN'; 2 | export const LOGIN_FAILED_NOT_EXISTED = 'LOGIN_FAILED_NOT_EXISTED'; 3 | export const LOGIN_FAILED_NOT_MATCH = 'LOGIN_FAILED_NOT_MATCH'; 4 | export const LOGOUT = 'LOGOUT'; 5 | export const REGISTER = 'REGISTER'; 6 | export const REGISTER_FAILED_EXISTED = 'REGISTER_FAILED_EXISTED'; -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo-item/todo-item.component.html: -------------------------------------------------------------------------------- 1 |
2 | check_circle 3 | 4 | 5 |
6 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/log-on-click.directive.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Directive, 3 | HostListener 4 | } from '@angular/core'; 5 | 6 | @Directive({ 7 | selector: "[log-on-click]", 8 | }) 9 | export class LogOnClickDirective { 10 | 11 | constructor() {} 12 | @HostListener('click') 13 | onClick() { console.log('I am clicked!'); } 14 | } -------------------------------------------------------------------------------- /angular2/playground/src/styles.scss: -------------------------------------------------------------------------------- 1 | @import "~angular2-mdl/scss/color-definitions"; 2 | 3 | $color-primary: $palette-blue-500; 4 | $color-primary-dark: $palette-blue-700; 5 | $color-accent: $palette-amber-A200; 6 | $color-primary-contrast: $color-dark-contrast; 7 | $color-accent-contrast: $color-dark-contrast; 8 | 9 | @import '~angular2-mdl/scss/material-design-lite'; 10 | -------------------------------------------------------------------------------- /angular/ng-tut/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | NgTut 6 | 7 | 8 | 9 | 10 | 11 | 12 | Loading... 13 | 14 | 15 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/two/two.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-two', 5 | templateUrl: './two.component.html', 6 | styleUrls: ['./two.component.css'] 7 | }) 8 | export class TwoComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /angular2/playground/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-root', 5 | templateUrl: './app.component.html', 6 | styleUrls: ['./app.component.css'] 7 | }) 8 | export class AppComponent { 9 | content = ``; 10 | } 11 | -------------------------------------------------------------------------------- /angular/ng-tut/e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { NgTutPage } from './app.po'; 2 | 3 | describe('ng-tut App', () => { 4 | let page: NgTutPage; 5 | 6 | beforeEach(() => { 7 | page = new NgTutPage(); 8 | }); 9 | 10 | it('should display message saying app works', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('app works!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/three/three.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-three', 5 | templateUrl: './three.component.html', 6 | styleUrls: ['./three.component.css'] 7 | }) 8 | export class ThreeComponent implements OnInit { 9 | 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /angular2/playground/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Playground 6 | 7 | 8 | 9 | 10 | 11 | 12 | Loading... 13 | 14 | 15 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |
5 | 6 |
7 |
8 | 9 | 10 | 11 |
12 | 13 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/one/one.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-one', 5 | templateUrl: './one.component.html', 6 | styleUrls: ['./one.component.css'] 7 | }) 8 | export class OneComponent implements OnInit { 9 | birthday = new Date(); 10 | constructor() { } 11 | 12 | ngOnInit() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /angular/ng-tut/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule); 12 | -------------------------------------------------------------------------------- /angular2/ng2-tut/e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { Ng2TutPage } from './app.po'; 2 | 3 | describe('ng2-tut App', function() { 4 | let page: Ng2TutPage; 5 | 6 | beforeEach(() => { 7 | page = new Ng2TutPage(); 8 | }); 9 | 10 | it('should display message saying app works', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('app works!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/src/app/login/login.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-login', 5 | template: ` 6 |

7 | login Works! 8 |

9 | `, 10 | styles: [] 11 | }) 12 | export class LoginComponent implements OnInit { 13 | 14 | constructor() { } 15 | 16 | ngOnInit() { 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HelloAngular 6 | 7 | 8 | 9 | 10 | 11 | 12 | Loading... 13 | 14 | 15 | -------------------------------------------------------------------------------- /angular/pragmatic/e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { PragmaticPage } from './app.po'; 2 | 3 | describe('pragmatic App', () => { 4 | let page: PragmaticPage; 5 | 6 | beforeEach(() => { 7 | page = new PragmaticPage(); 8 | }); 9 | 10 | it('should display message saying app works', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('app works!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /angular/pragmatic/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule); 12 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/core/footer/footer.component.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Component, 3 | OnInit 4 | } from '@angular/core'; 5 | 6 | @Component({ 7 | selector: 'app-footer', 8 | templateUrl: './footer.component.html', 9 | styleUrls: ['./footer.component.scss'] 10 | }) 11 | export class FooterComponent implements OnInit { 12 | 13 | constructor() { } 14 | 15 | ngOnInit() { 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /angular2/playground/e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { PlaygroundPage } from './app.po'; 2 | 3 | describe('playground App', function() { 4 | let page: PlaygroundPage; 5 | 6 | beforeEach(() => { 7 | page = new PlaygroundPage(); 8 | }); 9 | 10 | it('should display message saying app works', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('app works!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/src/main.ts: -------------------------------------------------------------------------------- 1 | import { enableProdMode } from '@angular/core'; 2 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 3 | 4 | import { AppModule } from './app/app.module'; 5 | import { environment } from './environments/environment'; 6 | 7 | if (environment.production) { 8 | enableProdMode(); 9 | } 10 | 11 | platformBrowserDynamic().bootstrapModule(AppModule); 12 | -------------------------------------------------------------------------------- /angular/ng-tut/src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "baseUrl": "", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | }, 13 | "files": [ 14 | "test.ts" 15 | ], 16 | "include": [ 17 | "**/*.spec.ts", 18 | "**/*.d.ts" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /angular/pragmatic/src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "baseUrl": "", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | }, 13 | "files": [ 14 | "test.ts" 15 | ], 16 | "include": [ 17 | "**/*.spec.ts", 18 | "**/*.d.ts" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /angular2/playground/src/main.ts: -------------------------------------------------------------------------------- 1 | import './polyfills.ts'; 2 | 3 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 4 | import { enableProdMode } from '@angular/core'; 5 | import { environment } from './environments/environment'; 6 | import { AppModule } from './app/'; 7 | 8 | if (environment.production) { 9 | enableProdMode(); 10 | } 11 | 12 | platformBrowserDynamic().bootstrapModule(AppModule); 13 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/main.ts: -------------------------------------------------------------------------------- 1 | import './polyfills.ts'; 2 | 3 | import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; 4 | import { enableProdMode } from '@angular/core'; 5 | import { environment } from './environments/environment'; 6 | import { AppModule } from './app/app.module'; 7 | 8 | if (environment.production) { 9 | enableProdMode(); 10 | } 11 | 12 | platformBrowserDynamic().bootstrapModule(AppModule); 13 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/e2e/app.e2e-spec.ts: -------------------------------------------------------------------------------- 1 | import { HelloAngularPage } from './app.po'; 2 | 3 | describe('hello-angular App', () => { 4 | let page: HelloAngularPage; 5 | 6 | beforeEach(() => { 7 | page = new HelloAngularPage(); 8 | }); 9 | 10 | it('should display message saying app works', () => { 11 | page.navigateTo(); 12 | expect(page.getParagraphText()).toEqual('app works!'); 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/src/tsconfig.spec.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out-tsc/spec", 5 | "module": "commonjs", 6 | "target": "es5", 7 | "baseUrl": "", 8 | "types": [ 9 | "jasmine", 10 | "node" 11 | ] 12 | }, 13 | "files": [ 14 | "test.ts" 15 | ], 16 | "include": [ 17 | "**/*.spec.ts", 18 | "**/*.d.ts" 19 | ] 20 | } 21 | -------------------------------------------------------------------------------- /angular/ng-tut/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // The file contents for the current environment will overwrite these during build. 2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do 3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead. 4 | // The list of which env maps to which file can be found in `.angular-cli.json`. 5 | 6 | export const environment = { 7 | production: false 8 | }; 9 | -------------------------------------------------------------------------------- /angular/pragmatic/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // The file contents for the current environment will overwrite these during build. 2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do 3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead. 4 | // The list of which env maps to which file can be found in `.angular-cli.json`. 5 | 6 | export const environment = { 7 | production: false 8 | }; 9 | -------------------------------------------------------------------------------- /angular2/ng2-tut/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "declaration": false, 5 | "emitDecoratorMetadata": true, 6 | "experimentalDecorators": true, 7 | "module": "commonjs", 8 | "moduleResolution": "node", 9 | "outDir": "../dist/out-tsc-e2e", 10 | "sourceMap": true, 11 | "target": "es5", 12 | "typeRoots": [ 13 | "../node_modules/@types" 14 | ] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // The file contents for the current environment will overwrite these during build. 2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do 3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead. 4 | // The list of which env maps to which file can be found in `angular-cli.json`. 5 | 6 | export const environment = { 7 | production: false 8 | }; 9 | -------------------------------------------------------------------------------- /angular2/playground/e2e/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "declaration": false, 5 | "emitDecoratorMetadata": true, 6 | "experimentalDecorators": true, 7 | "module": "commonjs", 8 | "moduleResolution": "node", 9 | "outDir": "../dist/out-tsc-e2e", 10 | "sourceMap": true, 11 | "target": "es5", 12 | "typeRoots": [ 13 | "../node_modules/@types" 14 | ] 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /angular2/playground/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // The file contents for the current environment will overwrite these during build. 2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do 3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead. 4 | // The list of which env maps to which file can be found in `angular-cli.json`. 5 | 6 | export const environment = { 7 | production: false 8 | }; 9 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/actions/todo.action.ts: -------------------------------------------------------------------------------- 1 | export const ADD_TODO = 'ADD_TODO'; 2 | export const REMOVE_TODO = 'REMOVE_TODO'; 3 | export const TOGGLE_TODO = 'TOGGLE_TODO'; 4 | export const TOGGLE_ALL = 'TOGGLE_ALL'; 5 | export const CLEAR_COMPLETED = 'CLEAR_COMPLETED'; 6 | export const FETCH_FROM_API = 'FETCH_FROM_API'; 7 | 8 | export const VisibilityFilters = { 9 | SHOW_ALL: 'ALL', 10 | SHOW_COMPLETED: 'COMPLETED', 11 | SHOW_ACTIVE: 'ACTIVE' 12 | } 13 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/src/environments/environment.ts: -------------------------------------------------------------------------------- 1 | // The file contents for the current environment will overwrite these during build. 2 | // The build system defaults to the dev environment which uses `environment.ts`, but if you do 3 | // `ng build --env=prod` then `environment.prod.ts` will be used instead. 4 | // The list of which env maps to which file can be found in `.angular-cli.json`. 5 | 6 | export const environment = { 7 | production: false 8 | }; 9 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/domain/entities.ts: -------------------------------------------------------------------------------- 1 | export interface Todo { 2 | id?: string; 3 | desc: string; 4 | completed: boolean; 5 | userId?: number; 6 | } 7 | export interface User { 8 | id?: number; 9 | username: string; 10 | password: string; 11 | } 12 | export interface Auth { 13 | user?: User; 14 | hasError: boolean; 15 | errMsg?: string; 16 | redirectUrl?: string; 17 | } 18 | export interface Image { 19 | contentUrl: string; 20 | name: string; 21 | } -------------------------------------------------------------------------------- /angular2/ng2-tut/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Awesome Todos 8 | 9 | 10 | 11 | 12 | Loading... 13 | 14 | 15 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/login/login-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { LoginComponent } from './login.component'; 4 | 5 | const routes: Routes = [ 6 | { 7 | path: 'login', 8 | component: LoginComponent 9 | } 10 | ]; 11 | 12 | @NgModule({ 13 | imports: [ RouterModule.forChild(routes) ], 14 | exports: [ RouterModule ] 15 | }) 16 | export class LoginRoutingModule { } 17 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { AuthGuardService } from './core/auth-guard.service'; 4 | 5 | const routes: Routes = [ 6 | { 7 | path: '', 8 | redirectTo: 'newng', 9 | pathMatch: 'full' 10 | } 11 | ]; 12 | 13 | @NgModule({ 14 | imports: [RouterModule.forRoot(routes)], 15 | exports: [RouterModule] 16 | }) 17 | export class AppRoutingModule { } -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo-footer/todo-footer.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input, Output, EventEmitter } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-todo-footer', 5 | templateUrl: './todo-footer.component.html', 6 | styleUrls: ['./todo-footer.component.css'] 7 | }) 8 | export class TodoFooterComponent { 9 | @Input() itemCount: number; 10 | @Output() onClear = new EventEmitter(); 11 | onClick(){ 12 | this.onClear.emit(true); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /angular2/playground/src/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "", 4 | "declaration": false, 5 | "emitDecoratorMetadata": true, 6 | "experimentalDecorators": true, 7 | "lib": ["es6", "dom"], 8 | "mapRoot": "./", 9 | "module": "es6", 10 | "moduleResolution": "node", 11 | "outDir": "../dist/out-tsc", 12 | "sourceMap": true, 13 | "target": "es5", 14 | "typeRoots": [ 15 | "../node_modules/@types" 16 | ] 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /angular/ng-tut/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "outDir": "./dist/out-tsc", 5 | "baseUrl": "src", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "moduleResolution": "node", 9 | "emitDecoratorMetadata": true, 10 | "experimentalDecorators": true, 11 | "target": "es5", 12 | "typeRoots": [ 13 | "node_modules/@types" 14 | ], 15 | "lib": [ 16 | "es2016", 17 | "dom" 18 | ] 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /angular/pragmatic/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "outDir": "./dist/out-tsc", 5 | "baseUrl": "src", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "moduleResolution": "node", 9 | "emitDecoratorMetadata": true, 10 | "experimentalDecorators": true, 11 | "target": "es5", 12 | "typeRoots": [ 13 | "node_modules/@types" 14 | ], 15 | "lib": [ 16 | "es2016", 17 | "dom" 18 | ] 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/shared/shared.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { MaterialModule } from '@angular/material'; 5 | 6 | @NgModule({ 7 | imports: [ 8 | CommonModule, 9 | FormsModule, 10 | MaterialModule 11 | ], 12 | exports: [ 13 | CommonModule, 14 | FormsModule, 15 | MaterialModule 16 | ] 17 | }) 18 | export class SharedModule { } 19 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/core/auth-guard.service.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, inject } from '@angular/core/testing'; 2 | 3 | import { AuthGuardService } from './auth-guard.service'; 4 | 5 | describe('AuthGuardService', () => { 6 | beforeEach(() => { 7 | TestBed.configureTestingModule({ 8 | providers: [AuthGuardService] 9 | }); 10 | }); 11 | 12 | it('should ...', inject([AuthGuardService], (service: AuthGuardService) => { 13 | expect(service).toBeTruthy(); 14 | })); 15 | }); 16 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/core/header/header.component.html: -------------------------------------------------------------------------------- 1 | 2 | 5 | Angular 小操场 6 | 7 | 8 | {{(auth$|async).user.name}} 9 | 10 | 11 | 登录 12 | 13 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/core/auth.service.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | 3 | import { TestBed, async, inject } from '@angular/core/testing'; 4 | import { AuthService } from './auth.service'; 5 | 6 | describe('AuthService', () => { 7 | beforeEach(() => { 8 | TestBed.configureTestingModule({ 9 | providers: [AuthService] 10 | }); 11 | }); 12 | 13 | it('should ...', inject([AuthService], (service: AuthService) => { 14 | expect(service).toBeTruthy(); 15 | })); 16 | }); 17 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/core/user.service.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | 3 | import { TestBed, async, inject } from '@angular/core/testing'; 4 | import { UserService } from './user.service'; 5 | 6 | describe('UserService', () => { 7 | beforeEach(() => { 8 | TestBed.configureTestingModule({ 9 | providers: [UserService] 10 | }); 11 | }); 12 | 13 | it('should ...', inject([UserService], (service: UserService) => { 14 | expect(service).toBeTruthy(); 15 | })); 16 | }); 17 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo.service.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | 3 | import { TestBed, async, inject } from '@angular/core/testing'; 4 | import { TodoService } from './todo.service'; 5 | 6 | describe('TodoService', () => { 7 | beforeEach(() => { 8 | TestBed.configureTestingModule({ 9 | providers: [TodoService] 10 | }); 11 | }); 12 | 13 | it('should ...', inject([TodoService], (service: TodoService) => { 14 | expect(service).toBeTruthy(); 15 | })); 16 | }); 17 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": false, 3 | "compilerOptions": { 4 | "outDir": "./dist/out-tsc", 5 | "baseUrl": "src", 6 | "sourceMap": true, 7 | "declaration": false, 8 | "moduleResolution": "node", 9 | "emitDecoratorMetadata": true, 10 | "experimentalDecorators": true, 11 | "target": "es5", 12 | "typeRoots": [ 13 | "node_modules/@types" 14 | ], 15 | "lib": [ 16 | "es2016", 17 | "dom" 18 | ] 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/new-in-ng4/new-in-ng4.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { ReactiveComponent } from './reactive/reactive.component'; 3 | import { NewInNg4RoutingModule } from './new-in-ng4-routing.module'; 4 | import { SharedModule } from '../shared/shared.module'; 5 | 6 | @NgModule({ 7 | imports: [ 8 | SharedModule, 9 | NewInNg4RoutingModule 10 | ], 11 | exports: [ReactiveComponent], 12 | declarations: [ReactiveComponent] 13 | }) 14 | export class NewInNg4Module { } 15 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo.component.html: -------------------------------------------------------------------------------- 1 |
2 | 5 | 6 | 12 | 13 | 16 | 17 |
18 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo-list/todo-list.component.css: -------------------------------------------------------------------------------- 1 | .main { 2 | position: relative; 3 | z-index: 2; 4 | border-top: 1px solid #e6e6e6; 5 | } 6 | .todo-list { 7 | margin: 0; 8 | padding: 0; 9 | list-style: none; 10 | } 11 | .todo-list li { 12 | position: relative; 13 | font-size: 24px; 14 | border-bottom: 1px solid #ededed; 15 | } 16 | .toggle-all { 17 | position: absolute; 18 | top: -55px; 19 | left: -16px; 20 | width: 60px; 21 | height: 34px; 22 | text-align: center; 23 | } 24 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/core/auth-guard.service.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | 3 | import { TestBed, async, inject } from '@angular/core/testing'; 4 | import { AuthGuardService } from './auth-guard.service'; 5 | 6 | describe('AuthGuardService', () => { 7 | beforeEach(() => { 8 | TestBed.configureTestingModule({ 9 | providers: [AuthGuardService] 10 | }); 11 | }); 12 | 13 | it('should ...', inject([AuthGuardService], (service: AuthGuardService) => { 14 | expect(service).toBeTruthy(); 15 | })); 16 | }); 17 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/login/bing-image.service.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | 3 | import { TestBed, async, inject } from '@angular/core/testing'; 4 | import { BingImageService } from './bing-image.service'; 5 | 6 | describe('BingImageService', () => { 7 | beforeEach(() => { 8 | TestBed.configureTestingModule({ 9 | providers: [BingImageService] 10 | }); 11 | }); 12 | 13 | it('should ...', inject([BingImageService], (service: BingImageService) => { 14 | expect(service).toBeTruthy(); 15 | })); 16 | }); 17 | -------------------------------------------------------------------------------- /angular/ng-tut/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { HttpModule } from '@angular/http'; 5 | 6 | import { AppComponent } from './app.component'; 7 | 8 | @NgModule({ 9 | declarations: [ 10 | AppComponent 11 | ], 12 | imports: [ 13 | BrowserModule, 14 | FormsModule, 15 | HttpModule 16 | ], 17 | providers: [], 18 | bootstrap: [AppComponent] 19 | }) 20 | export class AppModule { } 21 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/new-in-ng4/new-in-ng4-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | import { ReactiveComponent } from './reactive/reactive.component'; 5 | 6 | const routes: Routes = [ 7 | { path: 'newng', component: ReactiveComponent, pathMatch: 'full' } 8 | ]; 9 | 10 | @NgModule({ 11 | imports: [RouterModule.forChild(routes)], 12 | exports: [RouterModule], 13 | }) 14 | export class NewInNg4RoutingModule { } 15 | export const routedComponents = [ReactiveComponent]; -------------------------------------------------------------------------------- /angular/pragmatic/src/app/app.component.scss: -------------------------------------------------------------------------------- 1 | // Import a pre-built theme 2 | @import '~@angular/material/core/theming/prebuilt/indigo-pink'; 3 | // Import your custom input theme file so you can call the custom-input-theme function 4 | @import 'src/styles.scss'; 5 | 6 | // Using the $theme variable from the pre-built theme you can call the theming function 7 | @include my-theme($theme); 8 | .site{ 9 | display: flex; 10 | flex-direction: column; 11 | min-height: 85vh; 12 | } 13 | 14 | .content{ 15 | flex: 1; 16 | } 17 | 18 | .sidenav { 19 | width: 200px; 20 | } -------------------------------------------------------------------------------- /angular/pragmatic/src/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Pragmatic 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | Loading... 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /angular2/playground/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | 7 | # dependencies 8 | /node_modules 9 | /bower_components 10 | 11 | # IDEs and editors 12 | /.idea 13 | /.vscode 14 | .project 15 | .classpath 16 | .c9/ 17 | *.launch 18 | .settings/ 19 | 20 | # misc 21 | /.sass-cache 22 | /connect.lock 23 | /coverage/* 24 | /libpeerconnection.log 25 | npm-debug.log 26 | testem.log 27 | /typings 28 | 29 | # e2e 30 | /e2e/*.js 31 | /e2e/*.map 32 | 33 | #System Files 34 | .DS_Store 35 | Thumbs.db 36 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo-list/todo-list.component.html: -------------------------------------------------------------------------------- 1 |
2 | expand_more 3 | 13 |
14 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "baseUrl": "", 4 | "declaration": false, 5 | "emitDecoratorMetadata": true, 6 | "experimentalDecorators": true, 7 | "lib": ["es6", "dom"], 8 | "mapRoot": "./", 9 | "module": "es6", 10 | "moduleResolution": "node", 11 | "outDir": "../dist/out-tsc", 12 | "sourceMap": true, 13 | "target": "es5", 14 | "typeRoots": [ 15 | "../node_modules/@types" 16 | ] 17 | }, 18 | "exclude": [ 19 | "test.ts" 20 | ], 21 | "angularCompilerOptions": { "genDir": "i18n" } 22 | } 23 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { TodoComponent } from './todo.component'; 4 | 5 | import { AuthGuardService } from '../core/auth-guard.service'; 6 | 7 | const routes: Routes = [ 8 | { 9 | path: 'todo/:filter', 10 | canActivate: [AuthGuardService], 11 | component: TodoComponent 12 | } 13 | ]; 14 | 15 | @NgModule({ 16 | imports: [ RouterModule.forChild(routes) ], 17 | exports: [ RouterModule ] 18 | }) 19 | export class TodoRoutingModule { } 20 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo-footer/todo-footer.component.html: -------------------------------------------------------------------------------- 1 | 12 | -------------------------------------------------------------------------------- /angular2/playground/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { HttpModule } from '@angular/http'; 5 | import { MdlModule } from 'angular2-mdl'; 6 | 7 | import { AppComponent } from './app.component'; 8 | 9 | @NgModule({ 10 | declarations: [ 11 | AppComponent 12 | ], 13 | imports: [ 14 | BrowserModule, 15 | FormsModule, 16 | HttpModule, 17 | MdlModule 18 | ], 19 | providers: [], 20 | bootstrap: [AppComponent] 21 | }) 22 | export class AppModule { } 23 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { CoreModule } from './core/core.module'; 4 | import { AppRoutingModule } from './app-routing.module'; 5 | import { AppComponent } from './app.component'; 6 | import { NewInNg4Module } from './new-in-ng4/new-in-ng4.module'; 7 | 8 | @NgModule({ 9 | declarations: [ 10 | AppComponent 11 | ], 12 | imports: [ 13 | BrowserModule, 14 | CoreModule, 15 | AppRoutingModule, 16 | NewInNg4Module 17 | ], 18 | bootstrap: [AppComponent] 19 | }) 20 | export class AppModule { } 21 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/utils/type.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This function coerces a string into a string literal type. 3 | * Using tagged union types in TypeScript 2.0, this enables 4 | * powerful typechecking of our reducers. 5 | * 6 | * Since every action label passes through this function it 7 | * is a good place to ensure all of our action labels 8 | * are unique. 9 | */ 10 | const typeCache: { [label: string]: boolean } = {}; 11 | 12 | export function type(label: T | ''): T { 13 | if (typeCache[label]) { 14 | throw new Error(`Action type "${label}" is not unique"`); 15 | } 16 | typeCache[label] = true; 17 | return label; 18 | } -------------------------------------------------------------------------------- /angular2/ng2-tut/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | 7 | # dependencies 8 | /node_modules 9 | /bower_components 10 | 11 | # IDEs and editors 12 | /.idea 13 | /.vscode 14 | .project 15 | .classpath 16 | .c9/ 17 | *.launch 18 | .settings/ 19 | chromeDummyDir/ 20 | 21 | # misc 22 | /.sass-cache 23 | /connect.lock 24 | /coverage/* 25 | /libpeerconnection.log 26 | npm-debug.log 27 | testem.log 28 | debug.log 29 | /typings 30 | 31 | # e2e 32 | /e2e/*.js 33 | /e2e/*.map 34 | 35 | # doc 36 | *.docx 37 | *.pdf 38 | 39 | #System Files 40 | .DS_Store 41 | Thumbs.db 42 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { FormsModule } from '@angular/forms'; 4 | import { HttpModule } from '@angular/http'; 5 | 6 | import { AppComponent } from './app.component'; 7 | import { LoginComponent } from './login/login.component'; 8 | 9 | @NgModule({ 10 | declarations: [ 11 | AppComponent, 12 | LoginComponent 13 | ], 14 | imports: [ 15 | BrowserModule, 16 | FormsModule, 17 | HttpModule 18 | ], 19 | providers: [], 20 | bootstrap: [AppComponent] 21 | }) 22 | export class AppModule { } 23 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/shared/shared.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { HttpModule } from '@angular/http'; 4 | import { MaterialModule } from '@angular/material'; 5 | import { FormsModule, ReactiveFormsModule } from '@angular/forms'; 6 | 7 | @NgModule({ 8 | imports: [ 9 | CommonModule, 10 | HttpModule, 11 | FormsModule, 12 | ReactiveFormsModule, 13 | MaterialModule 14 | ], 15 | exports: [ 16 | CommonModule, 17 | HttpModule, 18 | FormsModule, 19 | ReactiveFormsModule, 20 | MaterialModule 21 | ] 22 | }) 23 | export class SharedModule { } 24 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo-item/todo-item.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input, Output, EventEmitter } from '@angular/core'; 2 | 3 | @Component({ 4 | selector: 'app-todo-item', 5 | templateUrl: './todo-item.component.html', 6 | styleUrls: ['./todo-item.component.css'] 7 | }) 8 | export class TodoItemComponent{ 9 | @Input() isChecked: boolean = false; 10 | @Input() todoDesc: string = ''; 11 | @Output() onToggleTriggered = new EventEmitter(); 12 | @Output() onRemoveTriggered = new EventEmitter(); 13 | 14 | toggle() { 15 | this.onToggleTriggered.emit(true); 16 | } 17 | remove() { 18 | this.onRemoveTriggered.emit(true); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo-header/todo-header.component.css: -------------------------------------------------------------------------------- 1 | .new-todo { 2 | position: relative; 3 | margin: 0; 4 | width: 100%; 5 | font-size: 24px; 6 | font-family: inherit; 7 | font-weight: inherit; 8 | line-height: 1.4em; 9 | border: 0; 10 | color: inherit; 11 | padding: 6px; 12 | border: 1px solid #999; 13 | box-shadow: inset 0 -1px 5px 0 rgba(0, 0, 0, 0.2); 14 | box-sizing: border-box; 15 | -webkit-font-smoothing: antialiased; 16 | -moz-osx-font-smoothing: grayscale; 17 | padding: 16px 16px 16px 60px; 18 | border: none; 19 | background: rgba(0, 0, 0, 0.003); 20 | box-shadow: inset 0 -2px 1px rgba(0,0,0,0.03); 21 | } 22 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | // This file includes polyfills needed by Angular and is loaded before 2 | // the app. You can add your own extra polyfills to this file. 3 | import 'core-js/es6/symbol'; 4 | import 'core-js/es6/object'; 5 | import 'core-js/es6/function'; 6 | import 'core-js/es6/parse-int'; 7 | import 'core-js/es6/parse-float'; 8 | import 'core-js/es6/number'; 9 | import 'core-js/es6/math'; 10 | import 'core-js/es6/string'; 11 | import 'core-js/es6/date'; 12 | import 'core-js/es6/array'; 13 | import 'core-js/es6/regexp'; 14 | import 'core-js/es6/map'; 15 | import 'core-js/es6/set'; 16 | import 'core-js/es6/reflect'; 17 | 18 | import 'core-js/es7/reflect'; 19 | import 'zone.js/dist/zone'; 20 | -------------------------------------------------------------------------------- /angular2/playground/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | // This file includes polyfills needed by Angular 2 and is loaded before 2 | // the app. You can add your own extra polyfills to this file. 3 | import 'core-js/es6/symbol'; 4 | import 'core-js/es6/object'; 5 | import 'core-js/es6/function'; 6 | import 'core-js/es6/parse-int'; 7 | import 'core-js/es6/parse-float'; 8 | import 'core-js/es6/number'; 9 | import 'core-js/es6/math'; 10 | import 'core-js/es6/string'; 11 | import 'core-js/es6/date'; 12 | import 'core-js/es6/array'; 13 | import 'core-js/es6/regexp'; 14 | import 'core-js/es6/map'; 15 | import 'core-js/es6/set'; 16 | import 'core-js/es6/reflect'; 17 | 18 | import 'core-js/es7/reflect'; 19 | import 'zone.js/dist/zone'; 20 | -------------------------------------------------------------------------------- /angular/ng-tut/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | /node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | testem.log 34 | /typings 35 | 36 | # e2e 37 | /e2e/*.js 38 | /e2e/*.map 39 | 40 | # System Files 41 | .DS_Store 42 | Thumbs.db 43 | -------------------------------------------------------------------------------- /angular/pragmatic/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | /node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | testem.log 34 | /typings 35 | 36 | # e2e 37 | /e2e/*.js 38 | /e2e/*.map 39 | 40 | # System Files 41 | .DS_Store 42 | Thumbs.db 43 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/.gitignore: -------------------------------------------------------------------------------- 1 | # See http://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # compiled output 4 | /dist 5 | /tmp 6 | /out-tsc 7 | 8 | # dependencies 9 | /node_modules 10 | 11 | # IDEs and editors 12 | /.idea 13 | .project 14 | .classpath 15 | .c9/ 16 | *.launch 17 | .settings/ 18 | *.sublime-workspace 19 | 20 | # IDE - VSCode 21 | .vscode/* 22 | !.vscode/settings.json 23 | !.vscode/tasks.json 24 | !.vscode/launch.json 25 | !.vscode/extensions.json 26 | 27 | # misc 28 | /.sass-cache 29 | /connect.lock 30 | /coverage 31 | /libpeerconnection.log 32 | npm-debug.log 33 | testem.log 34 | /typings 35 | 36 | # e2e 37 | /e2e/*.js 38 | /e2e/*.map 39 | 40 | # System Files 41 | .DS_Store 42 | Thumbs.db 43 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/core/footer/footer.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { FooterComponent } from './footer.component'; 4 | 5 | describe('FooterComponent', () => { 6 | let component: FooterComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ FooterComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(FooterComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/core/header/header.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { HeaderComponent } from './header.component'; 4 | 5 | describe('HeaderComponent', () => { 6 | let component: HeaderComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ HeaderComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(HeaderComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/src/app/login/login.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { LoginComponent } from './login.component'; 4 | 5 | describe('LoginComponent', () => { 6 | let component: LoginComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ LoginComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(LoginComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/form-demo/form-demo.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, OnInit } from '@angular/core'; 2 | import { 3 | FormGroup, 4 | FormBuilder, 5 | Validators 6 | } from '@angular/forms'; 7 | 8 | @Component({ 9 | selector: 'app-form-demo', 10 | templateUrl: './form-demo.component.html', 11 | styleUrls: ['./form-demo.component.css'] 12 | }) 13 | export class FormDemoComponent implements OnInit { 14 | user: FormGroup; 15 | constructor(private fb: FormBuilder) { } 16 | 17 | ngOnInit() { 18 | this.user = this.fb.group({ 19 | name: ['', [Validators.required, Validators.minLength(2)]], 20 | account: this.fb.group({ 21 | email: ['', Validators.required], 22 | confirm: ['', Validators.required] 23 | }) 24 | }); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/domain/entities.interface.ts: -------------------------------------------------------------------------------- 1 | import { RouterState } from '@ngrx/router-store'; 2 | 3 | export interface User { 4 | id?: string; 5 | name: string; 6 | password?: string; 7 | gender?: boolean; 8 | phone?: string; 9 | } 10 | 11 | export interface Err { 12 | timestamp: Date; 13 | status: number; 14 | error: string; 15 | exception: string; 16 | message: string; 17 | path: string; 18 | } 19 | 20 | export interface Auth { 21 | user?: User; 22 | err?: Err; 23 | token?: string; 24 | } 25 | 26 | export interface AppState{ 27 | auth: Auth; 28 | router: RouterState; 29 | } 30 | 31 | export enum AgeUnit { 32 | Year = 0, 33 | Month, 34 | Day 35 | } 36 | 37 | export interface BirthDay{ 38 | age: number; 39 | ageUnit: number; 40 | dateOfBirth: string; 41 | } -------------------------------------------------------------------------------- /angular/pragmatic/src/app/new-in-ng4/reactive/reactive.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 2 | 3 | import { ReactiveComponent } from './reactive.component'; 4 | 5 | describe('ReactiveComponent', () => { 6 | let component: ReactiveComponent; 7 | let fixture: ComponentFixture; 8 | 9 | beforeEach(async(() => { 10 | TestBed.configureTestingModule({ 11 | declarations: [ ReactiveComponent ] 12 | }) 13 | .compileComponents(); 14 | })); 15 | 16 | beforeEach(() => { 17 | fixture = TestBed.createComponent(ReactiveComponent); 18 | component = fixture.componentInstance; 19 | fixture.detectChanges(); 20 | }); 21 | 22 | it('should create', () => { 23 | expect(component).toBeTruthy(); 24 | }); 25 | }); 26 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/app-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | import { LoginComponent } from './login/login.component'; 4 | import { AuthGuardService } from './core/auth-guard.service'; 5 | 6 | const routes: Routes = [ 7 | { 8 | path: '', 9 | redirectTo: 'login', 10 | pathMatch: 'full' 11 | }, 12 | { 13 | path: 'todo', 14 | redirectTo: 'todo/ALL', 15 | canLoad: [AuthGuardService] 16 | }, 17 | { 18 | path: 'playground', 19 | loadChildren: 'app/playground/playground.module#PlaygroundModule', 20 | } 21 | ]; 22 | 23 | @NgModule({ 24 | imports: [ 25 | RouterModule.forRoot(routes) 26 | ], 27 | exports: [ 28 | RouterModule 29 | ] 30 | }) 31 | export class AppRoutingModule {} 32 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/login/login.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { ReactiveFormsModule } from '@angular/forms'; 3 | import { SharedModule } from '../shared/shared.module'; 4 | import { BingImageService } from './bing-image.service'; 5 | import { LoginRoutingModule } from './login-routing.module'; 6 | import { LoginComponent } from './login.component'; 7 | import { RegisterDialogComponent } from './register-dialog.component'; 8 | 9 | @NgModule({ 10 | imports: [ 11 | SharedModule, 12 | LoginRoutingModule, 13 | ReactiveFormsModule 14 | ], 15 | declarations: [ 16 | LoginComponent, 17 | RegisterDialogComponent 18 | ], 19 | entryComponents: [RegisterDialogComponent], 20 | providers: [ 21 | BingImageService 22 | ] 23 | }) 24 | export class LoginModule { } 25 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/form-demo/form-demo.component.css: -------------------------------------------------------------------------------- 1 | .error { 2 | font-size: 13px; 3 | color: #c7254e; 4 | background: #f9f2f4; 5 | border-radius: 3px; 6 | padding: 15px; 7 | margin: -26px 0 15px; 8 | } 9 | label { 10 | display: block; 11 | } 12 | span { 13 | display: block; 14 | margin: 0 0 10px; 15 | } 16 | input { 17 | outline: 0; 18 | width: 100%; 19 | height: 50px; 20 | margin-bottom: 25px; 21 | padding: 0 15px 2px; 22 | font-size: 17px; 23 | background: #fff; 24 | border: 2px solid #ebebeb; 25 | border-radius: 4px; 26 | -webkit-box-shadow: inset 0 -2px #ebebeb; 27 | box-shadow: inset 0 -2px #ebebeb; 28 | &:focus { 29 | border-color: #62c2e4; 30 | outline: none; 31 | -webkit-box-shadow: inset 0 -2px #62c2e4; 32 | box-shadow: inset 0 -2px #62c2e4; 33 | } 34 | } -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo-item/todo-item.component.css: -------------------------------------------------------------------------------- 1 | .todoDesc { 2 | word-break: break-all; 3 | padding: 15px 15px 15px 15px; 4 | display: inline-flex; 5 | line-height: 1.2; 6 | transition: color 0.4s; 7 | } 8 | .label-completed { 9 | color: #d9d9d9; 10 | text-decoration: line-through; 11 | } 12 | .icon-completed { 13 | color: #3F51B5; 14 | } 15 | .destroy { 16 | display: none; 17 | position: absolute; 18 | top: 0; 19 | right: 10px; 20 | bottom: 0; 21 | width: 40px; 22 | height: 40px; 23 | margin: auto 0; 24 | font-size: 30px; 25 | color: #cc9a9a; 26 | margin-bottom: 11px; 27 | transition: color 0.2s ease-out; 28 | border: 0px; 29 | background-color: transparent; 30 | } 31 | .destroy:hover { 32 | color: #af5b5e; 33 | } 34 | .destroy:after { 35 | content: '×'; 36 | } 37 | .destroy { 38 | display: block; 39 | } 40 | -------------------------------------------------------------------------------- /angular/ng-tut/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './e2e/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | beforeLaunch: function() { 23 | require('ts-node').register({ 24 | project: 'e2e/tsconfig.e2e.json' 25 | }); 26 | }, 27 | onPrepare() { 28 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /angular/pragmatic/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './e2e/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | beforeLaunch: function() { 23 | require('ts-node').register({ 24 | project: 'e2e/tsconfig.e2e.json' 25 | }); 26 | }, 27 | onPrepare() { 28 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/one/one.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 3 | import { By } from '@angular/platform-browser'; 4 | import { DebugElement } from '@angular/core'; 5 | 6 | import { OneComponent } from './one.component'; 7 | 8 | describe('OneComponent', () => { 9 | let component: OneComponent; 10 | let fixture: ComponentFixture; 11 | 12 | beforeEach(async(() => { 13 | TestBed.configureTestingModule({ 14 | declarations: [ OneComponent ] 15 | }) 16 | .compileComponents(); 17 | })); 18 | 19 | beforeEach(() => { 20 | fixture = TestBed.createComponent(OneComponent); 21 | component = fixture.componentInstance; 22 | fixture.detectChanges(); 23 | }); 24 | 25 | it('should create', () => { 26 | expect(component).toBeTruthy(); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/two/two.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 3 | import { By } from '@angular/platform-browser'; 4 | import { DebugElement } from '@angular/core'; 5 | 6 | import { TwoComponent } from './two.component'; 7 | 8 | describe('TwoComponent', () => { 9 | let component: TwoComponent; 10 | let fixture: ComponentFixture; 11 | 12 | beforeEach(async(() => { 13 | TestBed.configureTestingModule({ 14 | declarations: [ TwoComponent ] 15 | }) 16 | .compileComponents(); 17 | })); 18 | 19 | beforeEach(() => { 20 | fixture = TestBed.createComponent(TwoComponent); 21 | component = fixture.componentInstance; 22 | fixture.detectChanges(); 23 | }); 24 | 25 | it('should create', () => { 26 | expect(component).toBeTruthy(); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 3 | import { By } from '@angular/platform-browser'; 4 | import { DebugElement } from '@angular/core'; 5 | 6 | import { TodoComponent } from './todo.component'; 7 | 8 | describe('TodoComponent', () => { 9 | let component: TodoComponent; 10 | let fixture: ComponentFixture; 11 | 12 | beforeEach(async(() => { 13 | TestBed.configureTestingModule({ 14 | declarations: [ TodoComponent ] 15 | }) 16 | .compileComponents(); 17 | })); 18 | 19 | beforeEach(() => { 20 | fixture = TestBed.createComponent(TodoComponent); 21 | component = fixture.componentInstance; 22 | fixture.detectChanges(); 23 | }); 24 | 25 | it('should create', () => { 26 | expect(component).toBeTruthy(); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/core/header/header.component.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Component, 3 | OnInit, 4 | Output, 5 | Input, 6 | EventEmitter 7 | } from '@angular/core'; 8 | import { Store } from '@ngrx/store'; 9 | import { AppState, Auth } from '../../domain/entities.interface'; 10 | import { Observable } from 'rxjs/Observable'; 11 | 12 | @Component({ 13 | selector: 'app-header', 14 | templateUrl: './header.component.html', 15 | styleUrls: ['./header.component.scss'] 16 | }) 17 | export class HeaderComponent implements OnInit { 18 | auth$: Observable; 19 | 20 | @Output("toggle") clickHandler: EventEmitter = new EventEmitter(); 21 | constructor( 22 | private store$: Store) { 23 | this.auth$ = this.store$.select(appState => appState.auth); 24 | } 25 | 26 | ngOnInit() { 27 | } 28 | 29 | onClick() { 30 | this.clickHandler.emit(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/app.module.ts: -------------------------------------------------------------------------------- 1 | import { BrowserModule } from '@angular/platform-browser'; 2 | import { NgModule } from '@angular/core'; 3 | import { MaterialModule } from '@angular/material'; 4 | import { FlexLayoutModule } from '@angular/flex-layout'; 5 | import { CoreModule } from './core/core.module'; 6 | import { AppRoutingModule } from './app-routing.module'; 7 | import { TodoModule } from './todo/todo.module'; 8 | import { LoginModule } from './login/login.module'; 9 | import { AppComponent } from './app.component'; 10 | import 'hammerjs'; 11 | 12 | @NgModule({ 13 | declarations: [ 14 | AppComponent 15 | ], 16 | imports: [ 17 | BrowserModule, 18 | CoreModule, 19 | AppRoutingModule, 20 | MaterialModule.forRoot(), 21 | FlexLayoutModule, 22 | LoginModule, 23 | TodoModule 24 | ], 25 | bootstrap: [ 26 | AppComponent 27 | ] 28 | }) 29 | export class AppModule { } 30 | -------------------------------------------------------------------------------- /angular2/ng2-tut/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | /*global jasmine */ 5 | var SpecReporter = require('jasmine-spec-reporter'); 6 | 7 | exports.config = { 8 | allScriptsTimeout: 11000, 9 | specs: [ 10 | './e2e/**/*.e2e-spec.ts' 11 | ], 12 | capabilities: { 13 | 'browserName': 'chrome' 14 | }, 15 | directConnect: true, 16 | baseUrl: 'http://localhost:4200/', 17 | framework: 'jasmine', 18 | jasmineNodeOpts: { 19 | showColors: true, 20 | defaultTimeoutInterval: 30000, 21 | print: function() {} 22 | }, 23 | useAllAngular2AppRoots: true, 24 | beforeLaunch: function() { 25 | require('ts-node').register({ 26 | project: 'e2e' 27 | }); 28 | }, 29 | onPrepare: function() { 30 | jasmine.getEnv().addReporter(new SpecReporter()); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/login/login.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 3 | import { By } from '@angular/platform-browser'; 4 | import { DebugElement } from '@angular/core'; 5 | 6 | import { LoginComponent } from './login.component'; 7 | 8 | describe('LoginComponent', () => { 9 | let component: LoginComponent; 10 | let fixture: ComponentFixture; 11 | 12 | beforeEach(async(() => { 13 | TestBed.configureTestingModule({ 14 | declarations: [ LoginComponent ] 15 | }) 16 | .compileComponents(); 17 | })); 18 | 19 | beforeEach(() => { 20 | fixture = TestBed.createComponent(LoginComponent); 21 | component = fixture.componentInstance; 22 | fixture.detectChanges(); 23 | }); 24 | 25 | it('should create', () => { 26 | expect(component).toBeTruthy(); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/lib/config.ts 3 | 4 | const { SpecReporter } = require('jasmine-spec-reporter'); 5 | 6 | exports.config = { 7 | allScriptsTimeout: 11000, 8 | specs: [ 9 | './e2e/**/*.e2e-spec.ts' 10 | ], 11 | capabilities: { 12 | 'browserName': 'chrome' 13 | }, 14 | directConnect: true, 15 | baseUrl: 'http://localhost:4200/', 16 | framework: 'jasmine', 17 | jasmineNodeOpts: { 18 | showColors: true, 19 | defaultTimeoutInterval: 30000, 20 | print: function() {} 21 | }, 22 | beforeLaunch: function() { 23 | require('ts-node').register({ 24 | project: 'e2e/tsconfig.e2e.json' 25 | }); 26 | }, 27 | onPrepare() { 28 | jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } })); 29 | } 30 | }; 31 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/three/three.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 3 | import { By } from '@angular/platform-browser'; 4 | import { DebugElement } from '@angular/core'; 5 | 6 | import { ThreeComponent } from './three.component'; 7 | 8 | describe('ThreeComponent', () => { 9 | let component: ThreeComponent; 10 | let fixture: ComponentFixture; 11 | 12 | beforeEach(async(() => { 13 | TestBed.configureTestingModule({ 14 | declarations: [ ThreeComponent ] 15 | }) 16 | .compileComponents(); 17 | })); 18 | 19 | beforeEach(() => { 20 | fixture = TestBed.createComponent(ThreeComponent); 21 | component = fixture.componentInstance; 22 | fixture.detectChanges(); 23 | }); 24 | 25 | it('should create', () => { 26 | expect(component).toBeTruthy(); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /angular2/playground/protractor.conf.js: -------------------------------------------------------------------------------- 1 | // Protractor configuration file, see link for more information 2 | // https://github.com/angular/protractor/blob/master/docs/referenceConf.js 3 | 4 | /*global jasmine */ 5 | var SpecReporter = require('jasmine-spec-reporter'); 6 | 7 | exports.config = { 8 | allScriptsTimeout: 11000, 9 | specs: [ 10 | './e2e/**/*.e2e-spec.ts' 11 | ], 12 | capabilities: { 13 | 'browserName': 'chrome' 14 | }, 15 | directConnect: true, 16 | baseUrl: 'http://localhost:4200/', 17 | framework: 'jasmine', 18 | jasmineNodeOpts: { 19 | showColors: true, 20 | defaultTimeoutInterval: 30000, 21 | print: function() {} 22 | }, 23 | useAllAngular2AppRoots: true, 24 | beforeLaunch: function() { 25 | require('ts-node').register({ 26 | project: 'e2e' 27 | }); 28 | }, 29 | onPrepare: function() { 30 | jasmine.getEnv().addReporter(new SpecReporter()); 31 | } 32 | }; 33 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo-item/todo-item.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 3 | import { By } from '@angular/platform-browser'; 4 | import { DebugElement } from '@angular/core'; 5 | 6 | import { TodoItemComponent } from './todo-item.component'; 7 | 8 | describe('TodoItemComponent', () => { 9 | let component: TodoItemComponent; 10 | let fixture: ComponentFixture; 11 | 12 | beforeEach(async(() => { 13 | TestBed.configureTestingModule({ 14 | declarations: [ TodoItemComponent ] 15 | }) 16 | .compileComponents(); 17 | })); 18 | 19 | beforeEach(() => { 20 | fixture = TestBed.createComponent(TodoItemComponent); 21 | component = fixture.componentInstance; 22 | fixture.detectChanges(); 23 | }); 24 | 25 | it('should create', () => { 26 | expect(component).toBeTruthy(); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo-list/todo-list.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 3 | import { By } from '@angular/platform-browser'; 4 | import { DebugElement } from '@angular/core'; 5 | 6 | import { TodoListComponent } from './todo-list.component'; 7 | 8 | describe('TodoListComponent', () => { 9 | let component: TodoListComponent; 10 | let fixture: ComponentFixture; 11 | 12 | beforeEach(async(() => { 13 | TestBed.configureTestingModule({ 14 | declarations: [ TodoListComponent ] 15 | }) 16 | .compileComponents(); 17 | })); 18 | 19 | beforeEach(() => { 20 | fixture = TestBed.createComponent(TodoListComponent); 21 | component = fixture.componentInstance; 22 | fixture.detectChanges(); 23 | }); 24 | 25 | it('should create', () => { 26 | expect(component).toBeTruthy(); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/app.component.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Todos 5 | 6 | 7 | 8 | 9 | {{title}} 10 | 11 | 12 | 13 | 14 | Todos 15 | {{(auth$ | async).user?.username}} 16 | 17 | Login 18 | 19 | 20 | Logout 21 | 22 | 23 | 24 |
25 | 26 |
27 |
-------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/form-demo/form-demo.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 3 | import { By } from '@angular/platform-browser'; 4 | import { DebugElement } from '@angular/core'; 5 | 6 | import { FormDemoComponent } from './form-demo.component'; 7 | 8 | describe('FormDemoComponent', () => { 9 | let component: FormDemoComponent; 10 | let fixture: ComponentFixture; 11 | 12 | beforeEach(async(() => { 13 | TestBed.configureTestingModule({ 14 | declarations: [ FormDemoComponent ] 15 | }) 16 | .compileComponents(); 17 | })); 18 | 19 | beforeEach(() => { 20 | fixture = TestBed.createComponent(FormDemoComponent); 21 | component = fixture.componentInstance; 22 | fixture.detectChanges(); 23 | }); 24 | 25 | it('should create', () => { 26 | expect(component).toBeTruthy(); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/playground.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 3 | import { By } from '@angular/platform-browser'; 4 | import { DebugElement } from '@angular/core'; 5 | 6 | import { PlaygroundComponent } from './playground.component'; 7 | 8 | describe('PlaygroundComponent', () => { 9 | let component: PlaygroundComponent; 10 | let fixture: ComponentFixture; 11 | 12 | beforeEach(async(() => { 13 | TestBed.configureTestingModule({ 14 | declarations: [ PlaygroundComponent ] 15 | }) 16 | .compileComponents(); 17 | })); 18 | 19 | beforeEach(() => { 20 | fixture = TestBed.createComponent(PlaygroundComponent); 21 | component = fixture.componentInstance; 22 | fixture.detectChanges(); 23 | }); 24 | 25 | it('should create', () => { 26 | expect(component).toBeTruthy(); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo-footer/todo-footer.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 3 | import { By } from '@angular/platform-browser'; 4 | import { DebugElement } from '@angular/core'; 5 | 6 | import { TodoFooterComponent } from './todo-footer.component'; 7 | 8 | describe('TodoFooterComponent', () => { 9 | let component: TodoFooterComponent; 10 | let fixture: ComponentFixture; 11 | 12 | beforeEach(async(() => { 13 | TestBed.configureTestingModule({ 14 | declarations: [ TodoFooterComponent ] 15 | }) 16 | .compileComponents(); 17 | })); 18 | 19 | beforeEach(() => { 20 | fixture = TestBed.createComponent(TodoFooterComponent); 21 | component = fixture.componentInstance; 22 | fixture.detectChanges(); 23 | }); 24 | 25 | it('should create', () => { 26 | expect(component).toBeTruthy(); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo-header/todo-header.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | import { async, ComponentFixture, TestBed } from '@angular/core/testing'; 3 | import { By } from '@angular/platform-browser'; 4 | import { DebugElement } from '@angular/core'; 5 | 6 | import { TodoHeaderComponent } from './todo-header.component'; 7 | 8 | describe('TodoHeaderComponent', () => { 9 | let component: TodoHeaderComponent; 10 | let fixture: ComponentFixture; 11 | 12 | beforeEach(async(() => { 13 | TestBed.configureTestingModule({ 14 | declarations: [ TodoHeaderComponent ] 15 | }) 16 | .compileComponents(); 17 | })); 18 | 19 | beforeEach(() => { 20 | fixture = TestBed.createComponent(TodoHeaderComponent); 21 | component = fixture.componentInstance; 22 | fixture.detectChanges(); 23 | }); 24 | 25 | it('should create', () => { 26 | expect(component).toBeTruthy(); 27 | }); 28 | }); 29 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/new-in-ng4/reactive/reactive.component.html: -------------------------------------------------------------------------------- 1 |
4 | 5 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 26 | YYYY/MM/DD格式输入 27 | 28 |
-------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/app.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Inject } from '@angular/core'; 2 | import { Router } from '@angular/router'; 3 | import { AuthService } from './core/auth.service'; 4 | import { Store } from '@ngrx/store'; 5 | import { AppState, Auth } from './domain/state'; 6 | import { Observable } from 'rxjs/Observable'; 7 | import { 8 | LOGOUT 9 | } from './actions/auth.action' 10 | 11 | @Component({ 12 | selector: 'app-root', 13 | templateUrl: './app.component.html', 14 | styleUrls: ['./app.component.css'] 15 | }) 16 | export class AppComponent { 17 | title = 'Awesome Todos'; 18 | auth$: Observable; 19 | constructor( 20 | private store$: Store, 21 | private router: Router){ 22 | this.auth$ = this.store$.select(appState => appState.auth); 23 | } 24 | login() { 25 | this.router.navigate(['login']); 26 | } 27 | logout(){ 28 | this.store$.dispatch({type: LOGOUT}); 29 | this.router.navigate(['login']); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/reducers/auth.reducer.ts: -------------------------------------------------------------------------------- 1 | import { Reducer, Action } from '@ngrx/store'; 2 | import { Auth } from '../domain/entities.interface'; 3 | import * as authAction from '../actions/auth.action'; 4 | 5 | const initialState: Auth = {} 6 | 7 | export function authReducer (state: Auth = initialState, action: authAction.Actions): Auth { 8 | switch (action.type) { 9 | case authAction.ActionTypes.LOGIN_SUCCESS: 10 | return Object.assign({}, action.payload); 11 | case authAction.ActionTypes.LOGIN_FAIL: 12 | return Object.assign({}, state, { 13 | err: action.payload 14 | }); 15 | case authAction.ActionTypes.LOGOUT: 16 | return initialState; 17 | case authAction.ActionTypes.REGISTER_SUCCESS: 18 | return Object.assign({}, action.payload); 19 | case authAction.ActionTypes.REGISTER_FAIL: 20 | return Object.assign({}, state, { 21 | err: action.payload 22 | }); 23 | default: 24 | return state; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo-list/todo-list.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input, Output, EventEmitter } from '@angular/core'; 2 | import { Todo } from '../../domain/entities'; 3 | 4 | @Component({ 5 | selector: 'app-todo-list', 6 | templateUrl: './todo-list.component.html', 7 | styleUrls: ['./todo-list.component.css'] 8 | }) 9 | export class TodoListComponent { 10 | _todos: Todo[] = []; 11 | @Input() 12 | set todos(todos:Todo[]){ 13 | if(todos !== null) 14 | this._todos = [...todos]; 15 | } 16 | get todos() { 17 | return this._todos; 18 | } 19 | @Output() onRemoveTodo = new EventEmitter(); 20 | @Output() onToggleTodo = new EventEmitter(); 21 | @Output() onToggleAll = new EventEmitter(); 22 | 23 | onRemoveTriggered(todo: Todo) { 24 | this.onRemoveTodo.emit(todo); 25 | } 26 | onToggleTriggered(todo: Todo) { 27 | this.onToggleTodo.emit(todo); 28 | } 29 | onToggleAllTriggered() { 30 | this.onToggleAll.emit(true); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { HttpModule } from '@angular/http'; 3 | import { SharedModule } from '../shared/shared.module'; 4 | 5 | import { TodoRoutingModule } from './todo-routing.module' 6 | 7 | import { TodoComponent } from './todo.component'; 8 | import { TodoFooterComponent } from './todo-footer/todo-footer.component'; 9 | import { TodoHeaderComponent } from './todo-header/todo-header.component'; 10 | import { TodoService } from './todo.service'; 11 | import { TodoItemComponent } from './todo-item/todo-item.component'; 12 | import { TodoListComponent } from './todo-list/todo-list.component'; 13 | 14 | @NgModule({ 15 | imports: [ 16 | SharedModule, 17 | HttpModule, 18 | TodoRoutingModule 19 | ], 20 | declarations: [ 21 | TodoComponent, 22 | TodoFooterComponent, 23 | TodoHeaderComponent, 24 | TodoItemComponent, 25 | TodoListComponent 26 | ], 27 | providers: [ 28 | TodoService 29 | ], 30 | }) 31 | export class TodoModule {} 32 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/core/auth-guard.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { 3 | CanActivate, 4 | CanLoad, 5 | Router, 6 | Route, 7 | ActivatedRouteSnapshot, 8 | RouterStateSnapshot } from '@angular/router'; 9 | import { Observable } from 'rxjs/Observable'; 10 | import { Store } from '@ngrx/store'; 11 | import { AppState } from '../domain/entities.interface'; 12 | 13 | @Injectable() 14 | export class AuthGuardService implements CanActivate, CanLoad { 15 | 16 | constructor(private router: Router, private store$: Store) { } 17 | canActivate( 18 | route: ActivatedRouteSnapshot, 19 | state: RouterStateSnapshot 20 | ): Observable { 21 | const url: string = state.url; 22 | 23 | return this.store$.select(appState => appState.auth) 24 | .map(auth => auth.err !== undefined); 25 | } 26 | canLoad(route: Route): Observable { 27 | let url = `/${route.path}`; 28 | return this.store$.select(appState => appState.auth) 29 | .map(auth => auth.err !== undefined); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/playground.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { SharedModule } from '../shared/shared.module'; 3 | import { ReactiveFormsModule } from '@angular/forms'; 4 | import { PlaygroundRoutingModule } from './playground-routing.module'; 5 | import { PlaygroundComponent } from './playground.component'; 6 | import { OneComponent } from './one/one.component'; 7 | import { TwoComponent } from './two/two.component'; 8 | import { ThreeComponent } from './three/three.component'; 9 | import { FormDemoComponent } from './form-demo/form-demo.component'; 10 | import { TrimSpacePipe } from './trim-space.pipe'; 11 | import { LogOnClickDirective } from './log-on-click.directive'; 12 | 13 | @NgModule({ 14 | imports: [ 15 | SharedModule, 16 | ReactiveFormsModule, 17 | PlaygroundRoutingModule 18 | ], 19 | declarations: [ 20 | PlaygroundComponent, 21 | OneComponent, 22 | TwoComponent, 23 | ThreeComponent, 24 | FormDemoComponent, 25 | TrimSpacePipe, 26 | LogOnClickDirective 27 | ] 28 | }) 29 | export class PlaygroundModule { } 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)* 4 | 5 | - [awesome-tutorials](#awesome-tutorials) 6 | - [[ Angular 2.0 从0到1 ][1]](#-angular-20-%E4%BB%8E0%E5%88%B01-1) 7 | 8 | 9 | 10 | # awesome-tutorials 11 | I am going to write a series of tutorials about web/android/ios development 12 | 13 | 14 | 更深入的 Angular 学习,我已经在慕课网录了一门进阶的视频课,使用 Material, Rxjs, Redux 打造企业级应用 15 | http://coding.imooc.com/class/123.html 16 | 17 | 18 | 有问题的童鞋可以加入我的小密圈讨论: 19 | 我正在「学习是一种习惯」和朋友们讨论有趣的话题,你一起来吧? 20 | http://t.xiaomiquan.com/AiqB6eU 21 | (该链接6天内(5月31日前)有效) 22 | 23 | Angular 2.x 24 | 25 | ## [ Angular 2.0 从0到1 ][1] 26 | 27 | Spring Boot 28 | 29 | ## [ 重拾后端之Spring Boot ][2] 30 | 31 | [1]: https://github.com/wpcfan/awesome-tutorials/blob/master/angular2/ng2-tut/README.md 32 | 33 | [2]: https://github.com/wpcfan/spring-boot-tut/blob/master/README.md 34 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/core/auth-guard.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, Inject } from '@angular/core'; 2 | import { 3 | CanActivate, 4 | CanLoad, 5 | Router, 6 | Route, 7 | ActivatedRouteSnapshot, 8 | RouterStateSnapshot } from '@angular/router'; 9 | import { Observable } from 'rxjs/Observable'; 10 | import 'rxjs/add/operator/map'; 11 | import { Store } from '@ngrx/store'; 12 | import { AppState } from '../domain/state'; 13 | 14 | @Injectable() 15 | export class AuthGuardService implements CanActivate, CanLoad { 16 | 17 | constructor( 18 | private router: Router, 19 | private store$: Store) { } 20 | 21 | canActivate( 22 | route: ActivatedRouteSnapshot, 23 | state: RouterStateSnapshot 24 | ): Observable { 25 | const url: string = state.url; 26 | 27 | return this.store$.select(appState => appState.auth) 28 | .map(auth => !auth.hasError); 29 | } 30 | canLoad(route: Route): Observable { 31 | let url = `/${route.path}`; 32 | return this.store$.select(appState => appState.auth) 33 | .map(auth => !auth.hasError); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/test.ts: -------------------------------------------------------------------------------- 1 | import './polyfills.ts'; 2 | 3 | import 'zone.js/dist/long-stack-trace-zone'; 4 | import 'zone.js/dist/proxy.js'; 5 | import 'zone.js/dist/sync-test'; 6 | import 'zone.js/dist/jasmine-patch'; 7 | import 'zone.js/dist/async-test'; 8 | import 'zone.js/dist/fake-async-test'; 9 | import { getTestBed } from '@angular/core/testing'; 10 | import { 11 | BrowserDynamicTestingModule, 12 | platformBrowserDynamicTesting 13 | } from '@angular/platform-browser-dynamic/testing'; 14 | 15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. 16 | declare var __karma__: any; 17 | declare var require: any; 18 | 19 | // Prevent Karma from running prematurely. 20 | __karma__.loaded = function () {}; 21 | 22 | // First, initialize the Angular testing environment. 23 | getTestBed().initTestEnvironment( 24 | BrowserDynamicTestingModule, 25 | platformBrowserDynamicTesting() 26 | ); 27 | // Then we find all the tests. 28 | const context = require.context('./', true, /\.spec\.ts$/); 29 | // And load the modules. 30 | context.keys().map(context); 31 | // Finally, start Karma to run the tests. 32 | __karma__.start(); 33 | -------------------------------------------------------------------------------- /angular2/playground/src/test.ts: -------------------------------------------------------------------------------- 1 | import './polyfills.ts'; 2 | 3 | import 'zone.js/dist/long-stack-trace-zone'; 4 | import 'zone.js/dist/proxy.js'; 5 | import 'zone.js/dist/sync-test'; 6 | import 'zone.js/dist/jasmine-patch'; 7 | import 'zone.js/dist/async-test'; 8 | import 'zone.js/dist/fake-async-test'; 9 | import { getTestBed } from '@angular/core/testing'; 10 | import { 11 | BrowserDynamicTestingModule, 12 | platformBrowserDynamicTesting 13 | } from '@angular/platform-browser-dynamic/testing'; 14 | 15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. 16 | declare var __karma__: any; 17 | declare var require: any; 18 | 19 | // Prevent Karma from running prematurely. 20 | __karma__.loaded = function () {}; 21 | 22 | // First, initialize the Angular testing environment. 23 | getTestBed().initTestEnvironment( 24 | BrowserDynamicTestingModule, 25 | platformBrowserDynamicTesting() 26 | ); 27 | // Then we find all the tests. 28 | let context = require.context('./', true, /\.spec\.ts/); 29 | // And load the modules. 30 | context.keys().map(context); 31 | // Finally, start Karma to run the tests. 32 | __karma__.start(); 33 | -------------------------------------------------------------------------------- /angular/ng-tut/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | declarations: [ 9 | AppComponent 10 | ], 11 | }).compileComponents(); 12 | })); 13 | 14 | it('should create the app', async(() => { 15 | const fixture = TestBed.createComponent(AppComponent); 16 | const app = fixture.debugElement.componentInstance; 17 | expect(app).toBeTruthy(); 18 | })); 19 | 20 | it(`should have as title 'app works!'`, async(() => { 21 | const fixture = TestBed.createComponent(AppComponent); 22 | const app = fixture.debugElement.componentInstance; 23 | expect(app.title).toEqual('app works!'); 24 | })); 25 | 26 | it('should render title in a h1 tag', async(() => { 27 | const fixture = TestBed.createComponent(AppComponent); 28 | fixture.detectChanges(); 29 | const compiled = fixture.debugElement.nativeElement; 30 | expect(compiled.querySelector('h1').textContent).toContain('app works!'); 31 | })); 32 | }); 33 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | declarations: [ 9 | AppComponent 10 | ], 11 | }).compileComponents(); 12 | })); 13 | 14 | it('should create the app', async(() => { 15 | const fixture = TestBed.createComponent(AppComponent); 16 | const app = fixture.debugElement.componentInstance; 17 | expect(app).toBeTruthy(); 18 | })); 19 | 20 | it(`should have as title 'app works!'`, async(() => { 21 | const fixture = TestBed.createComponent(AppComponent); 22 | const app = fixture.debugElement.componentInstance; 23 | expect(app.title).toEqual('app works!'); 24 | })); 25 | 26 | it('should render title in a h1 tag', async(() => { 27 | const fixture = TestBed.createComponent(AppComponent); 28 | fixture.detectChanges(); 29 | const compiled = fixture.debugElement.nativeElement; 30 | expect(compiled.querySelector('h1').textContent).toContain('app works!'); 31 | })); 32 | }); 33 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | 3 | import { TestBed, async } from '@angular/core/testing'; 4 | import { AppComponent } from './app.component'; 5 | 6 | describe('AppComponent', () => { 7 | beforeEach(() => { 8 | TestBed.configureTestingModule({ 9 | declarations: [ 10 | AppComponent 11 | ], 12 | }); 13 | }); 14 | 15 | it('should create the app', async(() => { 16 | let fixture = TestBed.createComponent(AppComponent); 17 | let app = fixture.debugElement.componentInstance; 18 | expect(app).toBeTruthy(); 19 | })); 20 | 21 | it(`should have as title 'app works!'`, async(() => { 22 | let fixture = TestBed.createComponent(AppComponent); 23 | let app = fixture.debugElement.componentInstance; 24 | expect(app.title).toEqual('app works!'); 25 | })); 26 | 27 | it('should render title in a h1 tag', async(() => { 28 | let fixture = TestBed.createComponent(AppComponent); 29 | fixture.detectChanges(); 30 | let compiled = fixture.debugElement.nativeElement; 31 | expect(compiled.querySelector('h1').textContent).toContain('app works!'); 32 | })); 33 | }); 34 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/styles.scss: -------------------------------------------------------------------------------- 1 | @import '~@angular/material/core/theming/all-theme'; 2 | // Plus imports for other components in your app. 3 | 4 | // Include the base styles for Angular Material core. We include this here so that you only 5 | // have to load a single css file for Angular Material in your app. 6 | @include md-core(); 7 | 8 | // Define the palettes for your theme using the Material Design palettes available in palette.scss 9 | // (imported above). For each palette, you can optionally specify a default, lighter, and darker 10 | // hue. 11 | $ngtut-app-primary: md-palette($md-indigo); 12 | $ngtut-app-accent: md-palette($md-pink, A200, A100, A400); 13 | 14 | // The warn palette is optional (defaults to red). 15 | $ngtut-app-warn: md-palette($md-red); 16 | 17 | // Create the theme object (a Sass map containing all of the palettes). 18 | $ngtut-app-theme: md-light-theme($ngtut-app-primary, $ngtut-app-accent, $ngtut-app-warn); 19 | 20 | // Include theme styles for core and each component used in your app. 21 | // Alternatively, you can import and @include the theme mixins for each component 22 | // that you are using. 23 | @include angular-material-theme($ngtut-app-theme); -------------------------------------------------------------------------------- /angular2/playground/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-unused-variable */ 2 | 3 | import { TestBed, async } from '@angular/core/testing'; 4 | import { AppComponent } from './app.component'; 5 | 6 | describe('AppComponent', () => { 7 | beforeEach(() => { 8 | TestBed.configureTestingModule({ 9 | declarations: [ 10 | AppComponent 11 | ], 12 | }); 13 | }); 14 | 15 | it('should create the app', async(() => { 16 | let fixture = TestBed.createComponent(AppComponent); 17 | let app = fixture.debugElement.componentInstance; 18 | expect(app).toBeTruthy(); 19 | })); 20 | 21 | it(`should have as title 'app works!'`, async(() => { 22 | let fixture = TestBed.createComponent(AppComponent); 23 | let app = fixture.debugElement.componentInstance; 24 | expect(app.title).toEqual('app works!'); 25 | })); 26 | 27 | it('should render title in a h1 tag', async(() => { 28 | let fixture = TestBed.createComponent(AppComponent); 29 | fixture.detectChanges(); 30 | let compiled = fixture.debugElement.nativeElement; 31 | expect(compiled.querySelector('h1').textContent).toContain('app works!'); 32 | })); 33 | }); 34 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/src/app/app.component.spec.ts: -------------------------------------------------------------------------------- 1 | import { TestBed, async } from '@angular/core/testing'; 2 | 3 | import { AppComponent } from './app.component'; 4 | 5 | describe('AppComponent', () => { 6 | beforeEach(async(() => { 7 | TestBed.configureTestingModule({ 8 | declarations: [ 9 | AppComponent 10 | ], 11 | }).compileComponents(); 12 | })); 13 | 14 | it('should create the app', async(() => { 15 | const fixture = TestBed.createComponent(AppComponent); 16 | const app = fixture.debugElement.componentInstance; 17 | expect(app).toBeTruthy(); 18 | })); 19 | 20 | it(`should have as title 'app works!'`, async(() => { 21 | const fixture = TestBed.createComponent(AppComponent); 22 | const app = fixture.debugElement.componentInstance; 23 | expect(app.title).toEqual('app works!'); 24 | })); 25 | 26 | it('should render title in a h1 tag', async(() => { 27 | const fixture = TestBed.createComponent(AppComponent); 28 | fixture.detectChanges(); 29 | const compiled = fixture.debugElement.nativeElement; 30 | expect(compiled.querySelector('h1').textContent).toContain('app works!'); 31 | })); 32 | }); 33 | -------------------------------------------------------------------------------- /angular/ng-tut/README.md: -------------------------------------------------------------------------------- 1 | # NgTut 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.0.0. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive/pipe/service/class/module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | Before running the tests make sure you are serving the app via `ng serve`. 25 | 26 | ## Further help 27 | 28 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 29 | -------------------------------------------------------------------------------- /angular/pragmatic/README.md: -------------------------------------------------------------------------------- 1 | # Pragmatic 2 | 3 | This project was generated with [Angular CLI](https://github.com/angular/angular-cli) version 1.0.0. 4 | 5 | ## Development server 6 | 7 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 8 | 9 | ## Code scaffolding 10 | 11 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive/pipe/service/class/module`. 12 | 13 | ## Build 14 | 15 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build. 16 | 17 | ## Running unit tests 18 | 19 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 20 | 21 | ## Running end-to-end tests 22 | 23 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 24 | Before running the tests make sure you are serving the app via `ng serve`. 25 | 26 | ## Further help 27 | 28 | To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 29 | -------------------------------------------------------------------------------- /angular/ng-tut/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/long-stack-trace-zone'; 4 | import 'zone.js/dist/proxy.js'; 5 | import 'zone.js/dist/sync-test'; 6 | import 'zone.js/dist/jasmine-patch'; 7 | import 'zone.js/dist/async-test'; 8 | import 'zone.js/dist/fake-async-test'; 9 | import { getTestBed } from '@angular/core/testing'; 10 | import { 11 | BrowserDynamicTestingModule, 12 | platformBrowserDynamicTesting 13 | } from '@angular/platform-browser-dynamic/testing'; 14 | 15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. 16 | declare var __karma__: any; 17 | declare var require: any; 18 | 19 | // Prevent Karma from running prematurely. 20 | __karma__.loaded = function () {}; 21 | 22 | // First, initialize the Angular testing environment. 23 | getTestBed().initTestEnvironment( 24 | BrowserDynamicTestingModule, 25 | platformBrowserDynamicTesting() 26 | ); 27 | // Then we find all the tests. 28 | const context = require.context('./', true, /\.spec\.ts$/); 29 | // And load the modules. 30 | context.keys().map(context); 31 | // Finally, start Karma to run the tests. 32 | __karma__.start(); 33 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/core/core.module.ts: -------------------------------------------------------------------------------- 1 | import { ModuleWithProviders, NgModule, Optional, SkipSelf } from '@angular/core'; 2 | import { AuthService } from './auth.service'; 3 | import { UserService } from './user.service'; 4 | import { AuthGuardService } from './auth-guard.service'; 5 | 6 | import { HttpModule } from '@angular/http'; 7 | import { StoreModule } from '@ngrx/store'; 8 | import { todoReducer, todoFilterReducer } from '../reducers/todo.reducer'; 9 | import { authReducer } from '../reducers/auth.reducer'; 10 | import { StoreDevtoolsModule } from '@ngrx/store-devtools'; 11 | 12 | @NgModule({ 13 | imports:[ 14 | HttpModule, 15 | StoreModule.provideStore({ 16 | todos: todoReducer, 17 | todoFilter: todoFilterReducer, 18 | auth: authReducer 19 | }), 20 | StoreDevtoolsModule.instrumentOnlyWithExtension() 21 | ], 22 | providers: [ 23 | AuthService, 24 | UserService, 25 | AuthGuardService 26 | ] 27 | }) 28 | export class CoreModule { 29 | constructor (@Optional() @SkipSelf() parentModule: CoreModule) { 30 | if (parentModule) { 31 | throw new Error( 32 | 'CoreModule is already loaded. Import it in the AppModule only'); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /angular/pragmatic/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/long-stack-trace-zone'; 4 | import 'zone.js/dist/proxy.js'; 5 | import 'zone.js/dist/sync-test'; 6 | import 'zone.js/dist/jasmine-patch'; 7 | import 'zone.js/dist/async-test'; 8 | import 'zone.js/dist/fake-async-test'; 9 | import { getTestBed } from '@angular/core/testing'; 10 | import { 11 | BrowserDynamicTestingModule, 12 | platformBrowserDynamicTesting 13 | } from '@angular/platform-browser-dynamic/testing'; 14 | 15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. 16 | declare var __karma__: any; 17 | declare var require: any; 18 | 19 | // Prevent Karma from running prematurely. 20 | __karma__.loaded = function () {}; 21 | 22 | // First, initialize the Angular testing environment. 23 | getTestBed().initTestEnvironment( 24 | BrowserDynamicTestingModule, 25 | platformBrowserDynamicTesting() 26 | ); 27 | // Then we find all the tests. 28 | const context = require.context('./', true, /\.spec\.ts$/); 29 | // And load the modules. 30 | context.keys().map(context); 31 | // Finally, start Karma to run the tests. 32 | __karma__.start(); 33 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo-footer/todo-footer.component.css: -------------------------------------------------------------------------------- 1 | .footer { 2 | color: #777; 3 | padding: 10px 15px; 4 | height: 35px; 5 | text-align: center; 6 | border-top: 1px solid #e6e6e6; 7 | } 8 | .todo-count { 9 | float: left; 10 | text-align: left; 11 | } 12 | .todo-count strong { 13 | font-weight: 300; 14 | } 15 | .filters { 16 | margin: 0; 17 | padding: 0; 18 | list-style: none; 19 | position: absolute; 20 | right: 0; 21 | left: 0; 22 | } 23 | li { 24 | display: inline; 25 | } 26 | a { 27 | color: inherit; 28 | margin: 3px; 29 | padding: 3px 7px; 30 | text-decoration: none; 31 | border: 1px solid transparent; 32 | border-radius: 3px; 33 | } 34 | li a:hover { 35 | border-color: rgba(175, 47, 47, 0.1); 36 | } 37 | a.active { 38 | color: white; 39 | background-color: rgba(175, 47, 47, 0.2); 40 | border: none; 41 | } 42 | .clear-completed, .clear-completed:active { 43 | float: right; 44 | position: relative; 45 | line-height: 20px; 46 | text-decoration: none; 47 | cursor: pointer; 48 | background: transparent; 49 | border: none; 50 | } 51 | .clear-completed:hover { 52 | text-decoration: underline; 53 | } 54 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/src/test.ts: -------------------------------------------------------------------------------- 1 | // This file is required by karma.conf.js and loads recursively all the .spec and framework files 2 | 3 | import 'zone.js/dist/long-stack-trace-zone'; 4 | import 'zone.js/dist/proxy.js'; 5 | import 'zone.js/dist/sync-test'; 6 | import 'zone.js/dist/jasmine-patch'; 7 | import 'zone.js/dist/async-test'; 8 | import 'zone.js/dist/fake-async-test'; 9 | import { getTestBed } from '@angular/core/testing'; 10 | import { 11 | BrowserDynamicTestingModule, 12 | platformBrowserDynamicTesting 13 | } from '@angular/platform-browser-dynamic/testing'; 14 | 15 | // Unfortunately there's no typing for the `__karma__` variable. Just declare it as any. 16 | declare var __karma__: any; 17 | declare var require: any; 18 | 19 | // Prevent Karma from running prematurely. 20 | __karma__.loaded = function () {}; 21 | 22 | // First, initialize the Angular testing environment. 23 | getTestBed().initTestEnvironment( 24 | BrowserDynamicTestingModule, 25 | platformBrowserDynamicTesting() 26 | ); 27 | // Then we find all the tests. 28 | const context = require.context('./', true, /\.spec\.ts$/); 29 | // And load the modules. 30 | context.keys().map(context); 31 | // Finally, start Karma to run the tests. 32 | __karma__.start(); 33 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/data.json: -------------------------------------------------------------------------------- 1 | { 2 | "todos": [ 3 | { 4 | "id": "5894a12f-dae1-5ab0-5761-1371ba4f703e", 5 | "desc": "have breakfast", 6 | "completed": false, 7 | "userId": 2 8 | }, 9 | { 10 | "id": "6e628423-be05-204f-f075-527cc1bb10d8", 11 | "desc": "have lunch", 12 | "completed": false, 13 | "userId": 1 14 | }, 15 | { 16 | "id": "40ab7081-cab9-5900-4048-f4ea905afd2f", 17 | "desc": "take a break", 18 | "completed": false, 19 | "userId": 1 20 | }, 21 | { 22 | "id": "6ae06293-23d4-c0ca-ee5b-880365dbd48b", 23 | "desc": "having fun", 24 | "completed": false, 25 | "userId": 1 26 | }, 27 | { 28 | "id": "339bee66-995a-5fae-1fd5-217f1aaf11d5", 29 | "desc": "新的服务器版本不错", 30 | "completed": true, 31 | "userId": 1 32 | }, 33 | { 34 | "id": "c5182748-10d0-4f7f-0dd0-d66bdfb87df7", 35 | "desc": "使用Redux", 36 | "completed": false, 37 | "userId": 1 38 | } 39 | ], 40 | "users": [ 41 | { 42 | "id": 1, 43 | "username": "wang", 44 | "password": "1234" 45 | }, 46 | { 47 | "id": 2, 48 | "username": "peng", 49 | "password": "5678" 50 | } 51 | ] 52 | } -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/login/register-dialog.component.html: -------------------------------------------------------------------------------- 1 |
2 |

Register

3 |
4 | 5 | 6 | 7 |
8 |
9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 |
17 |
18 |
19 |

{{statusMessage}}

20 | 21 |
22 | 23 | 29 | 30 | 31 |
32 | -------------------------------------------------------------------------------- /angular2/.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | { 5 | "name": "Launch Chrome against localhost, with sourcemaps", 6 | "type": "chrome", 7 | "request": "launch", 8 | "url": "http://localhost:4200", 9 | "sourceMaps": true, 10 | "runtimeArgs": [ 11 | "--disable-session-crashed-bubble", 12 | "--disable-infobars" 13 | ], 14 | "diagnosticLogging": true, 15 | "webRoot": "${workspaceRoot}/src", 16 | //windows setup 17 | "userDataDir": "C:\\temp\\chromeDummyDir", 18 | "sourceMapPathOverrides": { 19 | "webpack:///C:*":"C:/*" 20 | //use "webpack:///*": "/*" on Linux/OSX 21 | } 22 | }, 23 | { 24 | "name": "Attach to Chrome, with sourcemaps", 25 | "type": "chrome", 26 | "request": "attach", 27 | "port": 9222, 28 | "sourceMaps": true, 29 | "diagnosticLogging": true, 30 | "webRoot": "${workspaceRoot}/src", 31 | "sourceMapPathOverrides": { 32 | "webpack:///C:*":"C:/*" 33 | } 34 | } 35 | ] 36 | } 37 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/playground-routing.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule } from '@angular/core'; 2 | import { Routes, RouterModule } from '@angular/router'; 3 | 4 | import { PlaygroundComponent } from './playground.component'; 5 | import { OneComponent } from './one/one.component'; 6 | import { TwoComponent } from './two/two.component'; 7 | import { ThreeComponent } from './three/three.component'; 8 | import { FormDemoComponent } from './form-demo/form-demo.component'; 9 | 10 | const routes: Routes = [ 11 | { 12 | path: '', 13 | component: PlaygroundComponent, 14 | children: [ 15 | { 16 | path: 'one', 17 | component: OneComponent, 18 | children: [ 19 | { 20 | path: 'three', 21 | component: ThreeComponent 22 | } 23 | ] 24 | }, 25 | { 26 | path: 'two', 27 | component: TwoComponent, 28 | children: [ 29 | { 30 | path: 'form', 31 | component: FormDemoComponent 32 | } 33 | ] 34 | } 35 | ] 36 | }, 37 | ]; 38 | 39 | @NgModule({ 40 | imports: [ RouterModule.forChild(routes) ], 41 | exports: [ RouterModule ], 42 | }) 43 | export class PlaygroundRoutingModule { } 44 | 45 | export const routedComponents = [PlaygroundComponent]; -------------------------------------------------------------------------------- /angular2/playground/README.md: -------------------------------------------------------------------------------- 1 | # Playground 2 | 3 | This project was generated with [angular-cli](https://github.com/angular/angular-cli) version 1.0.0-beta.21. 4 | 5 | ## Development server 6 | Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. 7 | 8 | ## Code scaffolding 9 | 10 | Run `ng generate component component-name` to generate a new component. You can also use `ng generate directive/pipe/service/class`. 11 | 12 | ## Build 13 | 14 | Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build. 15 | 16 | ## Running unit tests 17 | 18 | Run `ng test` to execute the unit tests via [Karma](https://karma-runner.github.io). 19 | 20 | ## Running end-to-end tests 21 | 22 | Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protractortest.org/). 23 | Before running the tests make sure you are serving the app via `ng serve`. 24 | 25 | ## Deploying to Github Pages 26 | 27 | Run `ng github-pages:deploy` to deploy to Github Pages. 28 | 29 | ## Further help 30 | 31 | To get more help on the `angular-cli` use `ng --help` or go check out the [Angular-CLI README](https://github.com/angular/angular-cli/blob/master/README.md). 32 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/login/bing-image.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | import { Http, Headers, Response } from '@angular/http'; 3 | import { Observable } from 'rxjs/Rx'; 4 | import { Image } from '../domain/entities'; 5 | 6 | @Injectable() 7 | export class BingImageService { 8 | 9 | imageUrl: string; 10 | headers = new Headers({ 11 | 'Content-Type': 'application/json', 12 | 'Ocp-Apim-Subscription-Key': '103ee07bf85a413e8212d556b011bf13' 13 | }); 14 | 15 | constructor(private http: Http) { 16 | const q = '北极+墙纸'; 17 | const baseUrl: string = `https://api.cognitive.microsoft.com/bing/v5.0/images/search`; 18 | this.imageUrl = baseUrl + `?q=${q}&count=5&mkt=zh-CN&imageType=Photo&size=Large`; 19 | } 20 | 21 | getImageUrl(): Observable{ 22 | return this.http.get(this.imageUrl, { headers: this.headers }) 23 | .map(res => res.json().value as Image[]) 24 | .catch(this.handleError); 25 | } 26 | private handleError(error: Response) { 27 |    console.error(error); 28 |    return Observable.throw(error.json().error || 'Server error'); 29 |   } 30 | // yieldByInterval(items, time) { 31 | // return Observable.from(items).zip( 32 | // Observable.interval(time), 33 | // (item, index) => item 34 | // ); 35 | // } 36 | } 37 | -------------------------------------------------------------------------------- /angular2/ng2-tut/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/0.13/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', 'angular-cli'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-remap-istanbul'), 12 | require('angular-cli/plugins/karma') 13 | ], 14 | files: [ 15 | { pattern: './src/test.ts', watched: false } 16 | ], 17 | preprocessors: { 18 | './src/test.ts': ['angular-cli'] 19 | }, 20 | mime: { 21 | 'text/x-typescript': ['ts','tsx'] 22 | }, 23 | remapIstanbulReporter: { 24 | reports: { 25 | html: 'coverage', 26 | lcovonly: './coverage/coverage.lcov' 27 | } 28 | }, 29 | angularCli: { 30 | config: './angular-cli.json', 31 | environment: 'dev' 32 | }, 33 | reporters: config.angularCli && config.angularCli.codeCoverage 34 | ? ['progress', 'karma-remap-istanbul'] 35 | : ['progress'], 36 | port: 9876, 37 | colors: true, 38 | logLevel: config.LOG_INFO, 39 | autoWatch: true, 40 | browsers: ['Chrome'], 41 | singleRun: false 42 | }); 43 | }; 44 | -------------------------------------------------------------------------------- /angular2/playground/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/0.13/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', 'angular-cli'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-remap-istanbul'), 12 | require('angular-cli/plugins/karma') 13 | ], 14 | files: [ 15 | { pattern: './src/test.ts', watched: false } 16 | ], 17 | preprocessors: { 18 | './src/test.ts': ['angular-cli'] 19 | }, 20 | mime: { 21 | 'text/x-typescript': ['ts','tsx'] 22 | }, 23 | remapIstanbulReporter: { 24 | reports: { 25 | html: 'coverage', 26 | lcovonly: './coverage/coverage.lcov' 27 | } 28 | }, 29 | angularCli: { 30 | config: './angular-cli.json', 31 | environment: 'dev' 32 | }, 33 | reporters: config.angularCli && config.angularCli.codeCoverage 34 | ? ['progress', 'karma-remap-istanbul'] 35 | : ['progress'], 36 | port: 9876, 37 | colors: true, 38 | logLevel: config.LOG_INFO, 39 | autoWatch: true, 40 | browsers: ['Chrome'], 41 | singleRun: false 42 | }); 43 | }; 44 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/login/login.component.html: -------------------------------------------------------------------------------- 1 | 48 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/actions/auth.action.ts: -------------------------------------------------------------------------------- 1 | import { Action } from '@ngrx/store'; 2 | import { type } from '../utils/type'; 3 | import { Auth, Err } from '../domain/entities.interface'; 4 | 5 | export const ActionTypes = { 6 | LOGIN_SUCCESS: type('[Auth] Login Success'), 7 | LOGIN_FAIL: type('[Err] Login Fail'), 8 | REGISTER_SUCCESS: type('[Auth] Register Success'), 9 | REGISTER_FAIL: type('[Err] Register Fail'), 10 | LOGOUT: type('[Auth] Logout') 11 | }; 12 | 13 | 14 | export class LoginSuccessAction implements Action { 15 | type = ActionTypes.LOGIN_SUCCESS; 16 | constructor(public payload: Auth){} 17 | } 18 | 19 | export class LoginFailAction implements Action { 20 | type = ActionTypes.LOGIN_FAIL; 21 | constructor(public payload: Err){} 22 | } 23 | 24 | export class RegisterSuccessAction implements Action { 25 | type = ActionTypes.REGISTER_SUCCESS; 26 | constructor(public payload: Auth){} 27 | } 28 | 29 | export class RegisterFailAction implements Action { 30 | type = ActionTypes.REGISTER_FAIL; 31 | constructor(public payload: Err){} 32 | } 33 | 34 | export class LogoutAction implements Action { 35 | type = ActionTypes.LOGOUT; 36 | constructor(public payload: Auth){} 37 | } 38 | 39 | export type Actions 40 | = LoginSuccessAction 41 | | LoginFailAction 42 | | RegisterSuccessAction 43 | | RegisterFailAction 44 | | LogoutAction; -------------------------------------------------------------------------------- /angular/ng-tut/.angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "project": { 4 | "name": "ng-tut" 5 | }, 6 | "apps": [ 7 | { 8 | "root": "src", 9 | "outDir": "dist", 10 | "assets": [ 11 | "assets", 12 | "favicon.ico" 13 | ], 14 | "index": "index.html", 15 | "main": "main.ts", 16 | "polyfills": "polyfills.ts", 17 | "test": "test.ts", 18 | "tsconfig": "tsconfig.app.json", 19 | "testTsconfig": "tsconfig.spec.json", 20 | "prefix": "app", 21 | "styles": [ 22 | "styles.css" 23 | ], 24 | "scripts": [], 25 | "environmentSource": "environments/environment.ts", 26 | "environments": { 27 | "dev": "environments/environment.ts", 28 | "prod": "environments/environment.prod.ts" 29 | } 30 | } 31 | ], 32 | "e2e": { 33 | "protractor": { 34 | "config": "./protractor.conf.js" 35 | } 36 | }, 37 | "lint": [ 38 | { 39 | "project": "src/tsconfig.app.json" 40 | }, 41 | { 42 | "project": "src/tsconfig.spec.json" 43 | }, 44 | { 45 | "project": "e2e/tsconfig.e2e.json" 46 | } 47 | ], 48 | "test": { 49 | "karma": { 50 | "config": "./karma.conf.js" 51 | } 52 | }, 53 | "defaults": { 54 | "styleExt": "css", 55 | "component": {} 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /angular/ng-tut/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ng-tut", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "scripts": { 6 | "ng": "ng", 7 | "start": "ng serve", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e" 12 | }, 13 | "private": true, 14 | "dependencies": { 15 | "@angular/common": "^4.0.0", 16 | "@angular/compiler": "^4.0.0", 17 | "@angular/core": "^4.0.0", 18 | "@angular/forms": "^4.0.0", 19 | "@angular/http": "^4.0.0", 20 | "@angular/platform-browser": "^4.0.0", 21 | "@angular/platform-browser-dynamic": "^4.0.0", 22 | "@angular/router": "^4.0.0", 23 | "core-js": "^2.4.1", 24 | "rxjs": "^5.1.0", 25 | "zone.js": "^0.8.4" 26 | }, 27 | "devDependencies": { 28 | "@angular/cli": "1.0.0", 29 | "@angular/compiler-cli": "^4.0.0", 30 | "@types/jasmine": "2.5.38", 31 | "@types/node": "~6.0.60", 32 | "codelyzer": "~2.0.0", 33 | "jasmine-core": "~2.5.2", 34 | "jasmine-spec-reporter": "~3.2.0", 35 | "karma": "~1.4.1", 36 | "karma-chrome-launcher": "~2.0.0", 37 | "karma-cli": "~1.0.1", 38 | "karma-jasmine": "~1.1.0", 39 | "karma-jasmine-html-reporter": "^0.2.2", 40 | "karma-coverage-istanbul-reporter": "^0.2.0", 41 | "protractor": "~5.1.0", 42 | "ts-node": "~2.0.0", 43 | "tslint": "~4.5.0", 44 | "typescript": "~2.2.0" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /angular/pragmatic/.angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "project": { 4 | "name": "pragmatic" 5 | }, 6 | "apps": [ 7 | { 8 | "root": "src", 9 | "outDir": "dist", 10 | "assets": [ 11 | "assets", 12 | "favicon.ico" 13 | ], 14 | "index": "index.html", 15 | "main": "main.ts", 16 | "polyfills": "polyfills.ts", 17 | "test": "test.ts", 18 | "tsconfig": "tsconfig.app.json", 19 | "testTsconfig": "tsconfig.spec.json", 20 | "prefix": "app", 21 | "styles": [ 22 | "styles.scss" 23 | ], 24 | "scripts": [], 25 | "environmentSource": "environments/environment.ts", 26 | "environments": { 27 | "dev": "environments/environment.ts", 28 | "prod": "environments/environment.prod.ts" 29 | } 30 | } 31 | ], 32 | "e2e": { 33 | "protractor": { 34 | "config": "./protractor.conf.js" 35 | } 36 | }, 37 | "lint": [ 38 | { 39 | "project": "src/tsconfig.app.json" 40 | }, 41 | { 42 | "project": "src/tsconfig.spec.json" 43 | }, 44 | { 45 | "project": "e2e/tsconfig.e2e.json" 46 | } 47 | ], 48 | "test": { 49 | "karma": { 50 | "config": "./karma.conf.js" 51 | } 52 | }, 53 | "defaults": { 54 | "styleExt": "scss", 55 | "component": {} 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /angular2/playground/angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "project": { 3 | "version": "1.0.0-beta.21", 4 | "name": "playground" 5 | }, 6 | "apps": [ 7 | { 8 | "root": "src", 9 | "outDir": "dist", 10 | "assets": [ 11 | "assets", 12 | "favicon.ico" 13 | ], 14 | "index": "index.html", 15 | "main": "main.ts", 16 | "test": "test.ts", 17 | "tsconfig": "tsconfig.json", 18 | "prefix": "app", 19 | "mobile": false, 20 | "styles": [ 21 | "styles.scss" 22 | ], 23 | "scripts": [], 24 | "environments": { 25 | "source": "environments/environment.ts", 26 | "dev": "environments/environment.ts", 27 | "prod": "environments/environment.prod.ts" 28 | } 29 | } 30 | ], 31 | "addons": [], 32 | "packages": [], 33 | "e2e": { 34 | "protractor": { 35 | "config": "./protractor.conf.js" 36 | } 37 | }, 38 | "test": { 39 | "karma": { 40 | "config": "./karma.conf.js" 41 | } 42 | }, 43 | "defaults": { 44 | "styleExt": "css", 45 | "prefixInterfaces": false, 46 | "inline": { 47 | "style": false, 48 | "template": false 49 | }, 50 | "spec": { 51 | "class": false, 52 | "component": true, 53 | "directive": true, 54 | "module": false, 55 | "pipe": true, 56 | "service": true 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo-header/todo-header.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Input, Output, EventEmitter, ElementRef } from '@angular/core'; 2 | import { Observable } from 'rxjs/Rx'; 3 | import 'rxjs/Observable'; 4 | import 'rxjs/add/operator/debounceTime'; 5 | import 'rxjs/add/operator/distinctUntilChanged'; 6 | 7 | @Component({ 8 | selector: 'app-todo-header', 9 | templateUrl: './todo-header.component.html', 10 | styleUrls: ['./todo-header.component.css'] 11 | }) 12 | export class TodoHeaderComponent { 13 | inputValue: string = ''; 14 | @Input() placeholder: string = 'What needs to be done?'; 15 | @Input() delay: number = 300; 16 | 17 | //detect the input value and output this to parent 18 | @Output() textChanges = new EventEmitter(); 19 | //detect the enter keyup event and output this to parent 20 | @Output() onEnterUp = new EventEmitter(); 21 | 22 | constructor(private elementRef: ElementRef) { 23 | const event$ = Observable.fromEvent(elementRef.nativeElement, 'input') 24 | .map(() => this.inputValue) 25 | .filter(input=> input.trim().length>0) 26 | .debounceTime(this.delay) 27 | .distinctUntilChanged(); 28 | event$.subscribe(input => this.textChanges.emit(input)); 29 | } 30 | enterUp(){ 31 | if(this.inputValue.trim().length===0) return; 32 | this.onEnterUp.emit(this.inputValue); 33 | this.inputValue = ''; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/.angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "./node_modules/@angular/cli/lib/config/schema.json", 3 | "project": { 4 | "name": "hello-angular" 5 | }, 6 | "apps": [ 7 | { 8 | "root": "src", 9 | "outDir": "dist", 10 | "assets": [ 11 | "assets", 12 | "favicon.ico" 13 | ], 14 | "index": "index.html", 15 | "main": "main.ts", 16 | "polyfills": "polyfills.ts", 17 | "test": "test.ts", 18 | "tsconfig": "tsconfig.app.json", 19 | "testTsconfig": "tsconfig.spec.json", 20 | "prefix": "app", 21 | "styles": [ 22 | "styles.css" 23 | ], 24 | "scripts": [], 25 | "environmentSource": "environments/environment.ts", 26 | "environments": { 27 | "dev": "environments/environment.ts", 28 | "prod": "environments/environment.prod.ts" 29 | } 30 | } 31 | ], 32 | "e2e": { 33 | "protractor": { 34 | "config": "./protractor.conf.js" 35 | } 36 | }, 37 | "lint": [ 38 | { 39 | "project": "src/tsconfig.app.json" 40 | }, 41 | { 42 | "project": "src/tsconfig.spec.json" 43 | }, 44 | { 45 | "project": "e2e/tsconfig.e2e.json" 46 | } 47 | ], 48 | "test": { 49 | "karma": { 50 | "config": "./karma.conf.js" 51 | } 52 | }, 53 | "defaults": { 54 | "styleExt": "css", 55 | "component": {} 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /angular2/ng2-tut/angular-cli.json: -------------------------------------------------------------------------------- 1 | { 2 | "project": { 3 | "version": "1.0.0-beta.25.5", 4 | "name": "ng2-tut" 5 | }, 6 | "apps": [ 7 | { 8 | "root": "src", 9 | "outDir": "dist", 10 | "assets": [ 11 | "assets", 12 | "favicon.ico" 13 | ], 14 | "index": "index.html", 15 | "main": "main.ts", 16 | "test": "test.ts", 17 | "tsconfig": "tsconfig.json", 18 | "prefix": "app", 19 | "mobile": false, 20 | "styles": [ 21 | "styles.css", 22 | "styles.scss" 23 | ], 24 | "scripts": [], 25 | "environments": { 26 | "source": "environments/environment.ts", 27 | "dev": "environments/environment.ts", 28 | "prod": "environments/environment.prod.ts" 29 | } 30 | } 31 | ], 32 | "addons": [], 33 | "packages": [], 34 | "e2e": { 35 | "protractor": { 36 | "config": "./protractor.conf.js" 37 | } 38 | }, 39 | "test": { 40 | "karma": { 41 | "config": "./karma.conf.js" 42 | } 43 | }, 44 | "defaults": { 45 | "styleExt": "css", 46 | "prefixInterfaces": false, 47 | "inline": { 48 | "style": false, 49 | "template": false 50 | }, 51 | "spec": { 52 | "class": false, 53 | "component": true, 54 | "directive": true, 55 | "module": false, 56 | "pipe": true, 57 | "service": true 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hello-angular", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "scripts": { 6 | "ng": "ng", 7 | "start": "ng serve", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e" 12 | }, 13 | "private": true, 14 | "dependencies": { 15 | "@angular/common": "^4.0.0", 16 | "@angular/compiler": "^4.0.0", 17 | "@angular/core": "^4.0.0", 18 | "@angular/forms": "^4.0.0", 19 | "@angular/http": "^4.0.0", 20 | "@angular/platform-browser": "^4.0.0", 21 | "@angular/platform-browser-dynamic": "^4.0.0", 22 | "@angular/router": "^4.0.0", 23 | "core-js": "^2.4.1", 24 | "rxjs": "^5.1.0", 25 | "zone.js": "^0.8.4" 26 | }, 27 | "devDependencies": { 28 | "@angular/cli": "1.0.0", 29 | "@angular/compiler-cli": "^4.0.0", 30 | "@types/jasmine": "2.5.38", 31 | "@types/node": "~6.0.60", 32 | "codelyzer": "~2.0.0", 33 | "jasmine-core": "~2.5.2", 34 | "jasmine-spec-reporter": "~3.2.0", 35 | "karma": "~1.4.1", 36 | "karma-chrome-launcher": "~2.0.0", 37 | "karma-cli": "~1.0.1", 38 | "karma-jasmine": "~1.1.0", 39 | "karma-jasmine-html-reporter": "^0.2.2", 40 | "karma-coverage-istanbul-reporter": "^0.2.0", 41 | "protractor": "~5.1.0", 42 | "ts-node": "~2.0.0", 43 | "tslint": "~4.5.0", 44 | "typescript": "~2.2.0" 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /angular/ng-tut/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/0.13/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular/cli'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular/cli/plugins/karma') 14 | ], 15 | client:{ 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | files: [ 19 | { pattern: './src/test.ts', watched: false } 20 | ], 21 | preprocessors: { 22 | './src/test.ts': ['@angular/cli'] 23 | }, 24 | mime: { 25 | 'text/x-typescript': ['ts','tsx'] 26 | }, 27 | coverageIstanbulReporter: { 28 | reports: [ 'html', 'lcovonly' ], 29 | fixWebpackSourcePaths: true 30 | }, 31 | angularCli: { 32 | environment: 'dev' 33 | }, 34 | reporters: config.angularCli && config.angularCli.codeCoverage 35 | ? ['progress', 'coverage-istanbul'] 36 | : ['progress', 'kjhtml'], 37 | port: 9876, 38 | colors: true, 39 | logLevel: config.LOG_INFO, 40 | autoWatch: true, 41 | browsers: ['Chrome'], 42 | singleRun: false 43 | }); 44 | }; 45 | -------------------------------------------------------------------------------- /angular/pragmatic/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/0.13/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular/cli'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular/cli/plugins/karma') 14 | ], 15 | client:{ 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | files: [ 19 | { pattern: './src/test.ts', watched: false } 20 | ], 21 | preprocessors: { 22 | './src/test.ts': ['@angular/cli'] 23 | }, 24 | mime: { 25 | 'text/x-typescript': ['ts','tsx'] 26 | }, 27 | coverageIstanbulReporter: { 28 | reports: [ 'html', 'lcovonly' ], 29 | fixWebpackSourcePaths: true 30 | }, 31 | angularCli: { 32 | environment: 'dev' 33 | }, 34 | reporters: config.angularCli && config.angularCli.codeCoverage 35 | ? ['progress', 'coverage-istanbul'] 36 | : ['progress', 'kjhtml'], 37 | port: 9876, 38 | colors: true, 39 | logLevel: config.LOG_INFO, 40 | autoWatch: true, 41 | browsers: ['Chrome'], 42 | singleRun: false 43 | }); 44 | }; 45 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/playground.component.html: -------------------------------------------------------------------------------- 1 | 8 | 17 | 18 | 23 | 24 | 28 | 29 | 31 | 32 | 34 | 35 | 41 | 42 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/karma.conf.js: -------------------------------------------------------------------------------- 1 | // Karma configuration file, see link for more information 2 | // https://karma-runner.github.io/0.13/config/configuration-file.html 3 | 4 | module.exports = function (config) { 5 | config.set({ 6 | basePath: '', 7 | frameworks: ['jasmine', '@angular/cli'], 8 | plugins: [ 9 | require('karma-jasmine'), 10 | require('karma-chrome-launcher'), 11 | require('karma-jasmine-html-reporter'), 12 | require('karma-coverage-istanbul-reporter'), 13 | require('@angular/cli/plugins/karma') 14 | ], 15 | client:{ 16 | clearContext: false // leave Jasmine Spec Runner output visible in browser 17 | }, 18 | files: [ 19 | { pattern: './src/test.ts', watched: false } 20 | ], 21 | preprocessors: { 22 | './src/test.ts': ['@angular/cli'] 23 | }, 24 | mime: { 25 | 'text/x-typescript': ['ts','tsx'] 26 | }, 27 | coverageIstanbulReporter: { 28 | reports: [ 'html', 'lcovonly' ], 29 | fixWebpackSourcePaths: true 30 | }, 31 | angularCli: { 32 | environment: 'dev' 33 | }, 34 | reporters: config.angularCli && config.angularCli.codeCoverage 35 | ? ['progress', 'coverage-istanbul'] 36 | : ['progress', 'kjhtml'], 37 | port: 9876, 38 | colors: true, 39 | logLevel: config.LOG_INFO, 40 | autoWatch: true, 41 | browsers: ['Chrome'], 42 | singleRun: false 43 | }); 44 | }; 45 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/core/user.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable } from '@angular/core'; 2 | 3 | import { Http, Headers, Response } from '@angular/http'; 4 | import { Observable } from 'rxjs/Rx'; 5 | import 'rxjs/add/operator/map'; 6 | 7 | import { User } from '../domain/entities'; 8 | 9 | @Injectable() 10 | export class UserService { 11 | 12 | private api_url = 'http://localhost:3000/users'; 13 | private headers = new Headers({'Content-Type': 'application/json'}); 14 | constructor(private http: Http) { } 15 | 16 | getUser(userId: number): Observable { 17 | const url = `${this.api_url}/${userId}`; 18 | return this.http.get(url) 19 | .map(res => res.json() as User); 20 | } 21 | findUser(username: string): Observable { 22 | const url = `${this.api_url}/?username=${username}`; 23 | return this.http.get(url) 24 | .map(res => { 25 | let users = res.json() as User[]; 26 | return (users.length>0) ? users[0] : null; 27 | }) 28 | .catch(this.handleError); 29 | } 30 | addUser(user: User): Observable{ 31 | return this.http.post(this.api_url, JSON.stringify(user), {headers: this.headers}) 32 | .map(res => res.json() as User) 33 | .catch(this.handleError); 34 | } 35 | private handleError(error: Response) { 36 |    console.error(error); 37 |    return Observable.throw(error.json().error || 'Server error'); 38 |   } 39 | } 40 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/form-demo/form-demo.component.html: -------------------------------------------------------------------------------- 1 |
2 | 6 |
7 | Name is required 8 |
9 |
10 | Minimum of 2 characters 11 |
12 |
13 | 17 |
20 | Email is required 21 |
22 | 26 |
29 | Confirming email is required 30 |
31 |
32 | 33 |
-------------------------------------------------------------------------------- /angular2/playground/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "playground", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "angular-cli": {}, 6 | "scripts": { 7 | "start": "ng serve", 8 | "lint": "tslint \"src/**/*.ts\"", 9 | "test": "ng test", 10 | "pree2e": "webdriver-manager update", 11 | "e2e": "protractor" 12 | }, 13 | "private": true, 14 | "dependencies": { 15 | "@angular/common": "2.2.1", 16 | "@angular/compiler": "2.2.1", 17 | "@angular/core": "2.2.1", 18 | "@angular/forms": "2.2.1", 19 | "@angular/http": "2.2.1", 20 | "@angular/platform-browser": "2.2.1", 21 | "@angular/platform-browser-dynamic": "2.2.1", 22 | "@angular/router": "3.2.1", 23 | "angular2-mdl": "^2.7.0", 24 | "core-js": "^2.4.1", 25 | "rxjs": "5.0.0-beta.12", 26 | "ts-helpers": "^1.1.1", 27 | "zone.js": "^0.6.23" 28 | }, 29 | "devDependencies": { 30 | "@angular/compiler-cli": "2.2.1", 31 | "@types/jasmine": "2.5.38", 32 | "@types/node": "^6.0.42", 33 | "angular-cli": "1.0.0-beta.21", 34 | "codelyzer": "~1.0.0-beta.3", 35 | "jasmine-core": "2.5.2", 36 | "jasmine-spec-reporter": "2.5.0", 37 | "karma": "1.2.0", 38 | "karma-chrome-launcher": "^2.0.0", 39 | "karma-cli": "^1.0.1", 40 | "karma-jasmine": "^1.0.2", 41 | "karma-remap-istanbul": "^0.2.1", 42 | "protractor": "4.0.9", 43 | "ts-node": "1.2.1", 44 | "tslint": "3.13.0", 45 | "typescript": "~2.0.3", 46 | "webdriver-manager": "10.2.5" 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/reducers/auth.reducer.ts: -------------------------------------------------------------------------------- 1 | import { Reducer, Action } from '@ngrx/store'; 2 | import { Auth } from '../domain/entities'; 3 | import { 4 | LOGIN_FAILED_NOT_EXISTED, 5 | LOGIN_FAILED_NOT_MATCH, 6 | LOGOUT, 7 | LOGIN, 8 | REGISTER, 9 | REGISTER_FAILED_EXISTED 10 | } from '../actions/auth.action'; 11 | 12 | export function authReducer (state: Auth = { 13 | user: null, 14 | hasError:true, 15 | errMsg: null, 16 | redirectUrl: null 17 | }, action: Action) { 18 | switch (action.type) { 19 | case LOGIN: 20 | return Object.assign({}, action.payload, {hasError: false}); 21 | case LOGIN_FAILED_NOT_EXISTED: 22 | return Object.assign({}, state, { 23 | user: null, 24 | hasError: true, 25 | errMsg: 'Username not existed' 26 | }); 27 | case LOGIN_FAILED_NOT_MATCH: 28 | return Object.assign({}, state, { 29 | user: null, 30 | hasError: true, 31 | errMsg: 'Password not match' 32 | }); 33 | case LOGOUT: 34 | return Object.assign({}, state, { 35 | user: null, 36 | hasError: true, 37 | errMsg: 'no credentials', 38 | redirectUrl: '/login' 39 | }); 40 | case REGISTER: 41 | return Object.assign({}, action.payload, {hasError: false}); 42 | case REGISTER_FAILED_EXISTED: 43 | return Object.assign({}, state, { 44 | user: null, 45 | hasError: true, 46 | errMsg: 'username existed' 47 | }); 48 | default: 49 | return state; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/reducers/todo.reducer.ts: -------------------------------------------------------------------------------- 1 | import { Reducer, Action } from '@ngrx/store'; 2 | import { Todo } from '../domain/entities'; 3 | import { 4 | ADD_TODO, 5 | REMOVE_TODO, 6 | TOGGLE_TODO, 7 | TOGGLE_ALL, 8 | CLEAR_COMPLETED, 9 | FETCH_FROM_API, 10 | VisibilityFilters 11 | } from '../actions/todo.action'; 12 | 13 | export function todoReducer (state: Todo[] =[], action: Action) { 14 | switch (action.type) { 15 | case ADD_TODO: 16 | return [ 17 | ...state, 18 | action.payload 19 | ]; 20 | case REMOVE_TODO: 21 | return state.filter(todo => todo.id !== action.payload.id); 22 | case TOGGLE_TODO: 23 | return state.map(todo => { 24 | if(todo.id !== action.payload.id){ 25 | return todo; 26 | } 27 | return Object.assign({}, todo, {completed: !todo.completed}); 28 | }); 29 | case TOGGLE_ALL: 30 | return state.map(todo => { 31 | return Object.assign({}, todo, {completed: !todo.completed}); 32 | }); 33 | case CLEAR_COMPLETED: 34 | return state.filter(todo => !todo.completed); 35 | case FETCH_FROM_API: 36 | return [ 37 | ...action.payload 38 | ]; 39 | default: 40 | return state; 41 | } 42 | } 43 | 44 | export function todoFilterReducer (state = (todo: Todo) => todo, action: Action) { 45 | switch (action.type) { 46 | case VisibilityFilters.SHOW_ALL: 47 | return todo => todo; 48 | case VisibilityFilters.SHOW_ACTIVE: 49 | return todo => !todo.completed; 50 | case VisibilityFilters.SHOW_COMPLETED: 51 | return todo => todo.completed; 52 | default: 53 | return state; 54 | } 55 | } -------------------------------------------------------------------------------- /angular/pragmatic/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pragmatic", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "scripts": { 6 | "ng": "ng", 7 | "start": "ng serve", 8 | "build": "ng build", 9 | "test": "ng test", 10 | "lint": "ng lint", 11 | "e2e": "ng e2e" 12 | }, 13 | "private": true, 14 | "dependencies": { 15 | "@angular/animations": "^4.0.1", 16 | "@angular/common": "^4.0.0", 17 | "@angular/compiler": "^4.0.0", 18 | "@angular/core": "^4.0.0", 19 | "@angular/flex-layout": "^2.0.0-rc.1", 20 | "@angular/forms": "^4.0.0", 21 | "@angular/http": "^4.0.0", 22 | "@angular/material": "^2.0.0-beta.2", 23 | "@angular/platform-browser": "^4.0.0", 24 | "@angular/platform-browser-dynamic": "^4.0.0", 25 | "@angular/router": "^4.0.0", 26 | "@ngrx/core": "^1.2.0", 27 | "@ngrx/effects": "^2.0.2", 28 | "@ngrx/router-store": "^1.2.5", 29 | "@ngrx/store": "^2.2.1", 30 | "@ngrx/store-devtools": "^3.2.4", 31 | "core-js": "^2.4.1", 32 | "hammerjs": "^2.0.8", 33 | "moment": "^2.18.1", 34 | "reselect": "^3.0.0", 35 | "rxjs": "^5.1.0", 36 | "zone.js": "^0.8.4" 37 | }, 38 | "devDependencies": { 39 | "@angular/cli": "1.0.0", 40 | "@angular/compiler-cli": "^4.0.0", 41 | "@types/jasmine": "2.5.38", 42 | "@types/node": "~6.0.60", 43 | "codelyzer": "~2.0.0", 44 | "jasmine-core": "~2.5.2", 45 | "jasmine-spec-reporter": "~3.2.0", 46 | "karma": "~1.4.1", 47 | "karma-chrome-launcher": "~2.0.0", 48 | "karma-cli": "~1.0.1", 49 | "karma-jasmine": "~1.1.0", 50 | "karma-jasmine-html-reporter": "^0.2.2", 51 | "karma-coverage-istanbul-reporter": "^0.2.0", 52 | "protractor": "~5.1.0", 53 | "ts-node": "~2.0.0", 54 | "tslint": "~4.5.0", 55 | "typescript": "~2.2.0" 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo.component.ts: -------------------------------------------------------------------------------- 1 | import { Component, Inject } from '@angular/core'; 2 | import { ActivatedRoute } from '@angular/router'; 3 | import { TodoService } from './todo.service'; 4 | 5 | import { AppState, Todo } from '../domain/state'; 6 | import { Store } from '@ngrx/store'; 7 | import { 8 | FETCH_FROM_API 9 | } from '../actions/todo.action' 10 | 11 | import { Observable } from 'rxjs/Observable'; 12 | 13 | @Component({ 14 | templateUrl: './todo.component.html', 15 | styleUrls: ['./todo.component.css'] 16 | }) 17 | export class TodoComponent { 18 | 19 | todos : Observable; 20 | 21 | constructor( 22 | private service: TodoService, 23 | private route: ActivatedRoute, 24 | private store$: Store) { 25 | const fetchData$ = this.service.getTodos() 26 | .flatMap(todos => { 27 | this.store$.dispatch({type: FETCH_FROM_API, payload: todos}); 28 | return this.store$.select('todos') 29 | }) 30 | .startWith([]); 31 | const filterData$ = this.route.params.pluck('filter') 32 | .do(value => { 33 | const filter = value as string; 34 | this.store$.dispatch({type: filter}); 35 | }) 36 | .flatMap(_ => this.store$.select('todoFilter')); 37 | this.todos = Observable.combineLatest( 38 | fetchData$, 39 | filterData$, 40 | (todos: Todo[], filter: any) => todos.filter(filter) 41 | ) 42 | } 43 | 44 | addTodo(desc: string) { 45 | this.service.addTodo(desc); 46 | } 47 | toggleTodo(todo: Todo) { 48 | this.service.toggleTodo(todo); 49 | } 50 | removeTodo(todo: Todo) { 51 | this.service.removeTodo(todo); 52 | } 53 | toggleAll(){ 54 | this.service.toggleAll(); 55 | } 56 | clearCompleted(){ 57 | this.service.clearCompleted(); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /angular/pragmatic/src/styles.scss: -------------------------------------------------------------------------------- 1 | /* You can add global styles to tmy file, and also import other style files */ 2 | @import '~@angular/material/core/theming/all-theme'; 3 | // Plus imports for other components in your app. 4 | 5 | // Include the base styles for Angular Material core. We include tmy here so that you only 6 | // have to load a single css file for Angular Material in your app. 7 | @include mat-core(); 8 | 9 | // Define the palettes for your theme using the Material Design palettes available in palette.scss 10 | // (imported above). For each palette, you can optionally specify a default, lighter, and darker 11 | // hue. 12 | $my-app-primary: mat-palette($mat-indigo); 13 | $my-app-accent: mat-palette($mat-pink, A200, A100, A400); 14 | 15 | // The warn palette is optional (defaults to red). 16 | $my-app-warn: mat-palette($mat-red); 17 | 18 | // Create the theme object (a Sass map containing all of the palettes). 19 | $my-app-theme: mat-light-theme($my-app-primary, $my-app-accent, $my-app-warn); 20 | 21 | // Include theme styles for core and each component used in your app. 22 | // Alternatively, you can import and @include the theme mixins for each component 23 | // that you are using. 24 | @include angular-material-theme($my-app-theme); 25 | 26 | // Define a mixin that accepts a theme and outputs the color styles for the component. 27 | @mixin my-theme($theme) { 28 | // Extract whichever individual palettes you need from the theme. 29 | $primary: map-get($theme, primary); 30 | $accent: map-get($theme, accent); 31 | 32 | // Use mat-color to extract individual colors from a palette as necessary. 33 | .my-container { 34 | background-color: mat-color($primary); 35 | border-color: mat-color($accent, A400); 36 | } 37 | } 38 | html, 39 | body { 40 | height: 100%; 41 | margin: 0; 42 | /* The html and body elements cannot have any padding or margin. */ 43 | } 44 | .spacer { 45 | flex: 1 1 auto; 46 | } -------------------------------------------------------------------------------- /angular2/ng2-tut/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ng2-tut", 3 | "version": "0.0.0", 4 | "license": "MIT", 5 | "angular-cli": {}, 6 | "scripts": { 7 | "ng": "ng", 8 | "start": "ng serve", 9 | "lint": "tslint \"src/**/*.ts\" --project src/tsconfig.json --type-check && tslint \"e2e/**/*.ts\" --project e2e/tsconfig.json --type-check", 10 | "test": "ng test", 11 | "pree2e": "webdriver-manager update --standalone false --gecko false", 12 | "e2e": "protractor", 13 | "i18n": "cd src && ng-xi18n" 14 | }, 15 | "private": true, 16 | "dependencies": { 17 | "@angular/common": "^2.3.1", 18 | "@angular/compiler": "^2.3.1", 19 | "@angular/core": "^2.3.1", 20 | "@angular/flex-layout": "^2.0.0-beta.1", 21 | "@angular/forms": "^2.3.1", 22 | "@angular/http": "^2.3.1", 23 | "@angular/material": "^2.0.0-beta.1", 24 | "@angular/platform-browser": "^2.3.1", 25 | "@angular/platform-browser-dynamic": "^2.3.1", 26 | "@angular/router": "^3.3.1", 27 | "@ngrx/core": "^1.2.0", 28 | "@ngrx/router-store": "^1.2.5", 29 | "@ngrx/store": "^2.2.1", 30 | "@ngrx/store-devtools": "^3.2.2", 31 | "angular2-uuid": "^1.1.0", 32 | "core-js": "^2.4.1", 33 | "hammerjs": "^2.0.8", 34 | "rxjs": "^5.0.1", 35 | "ts-helpers": "^1.1.1", 36 | "web-animations-js": "^2.2.2", 37 | "zone.js": "^0.7.2" 38 | }, 39 | "devDependencies": { 40 | "@angular/cli": "^1.0.0-beta.31", 41 | "@angular/compiler-cli": "^2.3.1", 42 | "@types/jasmine": "2.5.38", 43 | "@types/node": "^6.0.42", 44 | "codelyzer": "~2.0.0-beta.1", 45 | "jasmine-core": "2.5.2", 46 | "jasmine-spec-reporter": "2.5.0", 47 | "karma": "1.2.0", 48 | "karma-chrome-launcher": "^2.0.0", 49 | "karma-cli": "^1.0.1", 50 | "karma-jasmine": "^1.0.2", 51 | "karma-remap-istanbul": "^0.2.1", 52 | "protractor": "~4.0.13", 53 | "ts-node": "1.2.1", 54 | "tslint": "^4.3.0", 55 | "typescript": "~2.0.0" 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/core/core.module.ts: -------------------------------------------------------------------------------- 1 | import { NgModule, Optional, SkipSelf } from '@angular/core'; 2 | import { CommonModule } from '@angular/common'; 3 | import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; 4 | import { StoreModule } from '@ngrx/store'; 5 | import { routerReducer, RouterStoreModule } from '@ngrx/router-store'; 6 | import { HttpModule } from '@angular/http'; 7 | import { MaterialModule, MdSidenav, MdSidenavContainer } from '@angular/material'; 8 | import { FlexLayoutModule } from '@angular/flex-layout'; 9 | import { authReducer } from '../reducers/auth.reducer'; 10 | import { AuthGuardService } from './auth-guard.service'; 11 | import { StoreDevtoolsModule } from '@ngrx/store-devtools'; 12 | import { HeaderComponent } from './header/header.component'; 13 | import { FooterComponent } from './footer/footer.component'; 14 | 15 | import 'hammerjs'; 16 | 17 | @NgModule({ 18 | imports: [ 19 | CommonModule, 20 | BrowserAnimationsModule, 21 | MaterialModule, 22 | FlexLayoutModule, 23 | StoreModule.provideStore({ 24 | auth: authReducer 25 | }), 26 | RouterStoreModule.connectRouter(), 27 | // Note that you must instrument after importing StoreModule 28 | StoreDevtoolsModule.instrumentOnlyWithExtension({ 29 | maxAge: 5 30 | }) 31 | ], 32 | exports:[ 33 | FlexLayoutModule, 34 | HeaderComponent, 35 | FooterComponent, 36 | MdSidenav, 37 | MdSidenavContainer 38 | ], 39 | providers:[ 40 | AuthGuardService, 41 | { 42 | provide: 'API_BASE_URL', 43 | useValue: 'http://localhost:8090' 44 | }, 45 | { 46 | provide: 'APP_NAME', 47 | useValue: 'Angular 场景实战' 48 | }, 49 | { 50 | provide: 'COMPANY_NAME', 51 | useValue: 'COMPANY NAME' 52 | } 53 | ], 54 | declarations: [HeaderComponent, FooterComponent] 55 | }) 56 | export class CoreModule { 57 | constructor (@Optional() @SkipSelf() parentModule: CoreModule) { 58 | if (parentModule) { 59 | throw new Error( 60 | 'CoreModule is already loaded. Import it in the AppModule only'); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/playground/playground.component.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Component, 3 | OnDestroy, 4 | trigger, 5 | state, 6 | style, 7 | transition, 8 | animate, 9 | keyframes 10 | } from '@angular/core'; 11 | 12 | // import { Observable } from 'rxjs/Observable'; 13 | // import 'rxjs/add/observable/interval'; 14 | 15 | @Component({ 16 | selector: 'app-playground', 17 | templateUrl: './playground.component.html', 18 | styleUrls: ['./playground.component.css'], 19 | animations: [ 20 | trigger('signal', [ 21 | state('void', style({ 22 | 'transform':'translateY(-100%)' 23 | })), 24 | state('go', style({ 25 | 'background-color': 'green', 26 | 'height':'100px' 27 | })), 28 | state('stop', style({ 29 | 'background-color':'red', 30 | 'height':'50px' 31 | })), 32 | transition('void => *', animate(5000, keyframes([ 33 | style({'transform': 'scale(0)', 'padding': '0px'}), 34 | style({'transform': 'scale(0.1)', 'padding': '50px'}), 35 | style({'transform': 'scale(0.5)', 'padding': '100px'}), 36 | style({'transform': 'scale(0.9)', 'padding': '120px'}), 37 | style({'transform': 'scale(0.95)', 'padding': '135px'}), 38 | style({'transform': 'scale(1)', 'padding': '140px'}) 39 | ]))), 40 | transition('* => *', animate('.5s 1s cubic-bezier(0.175, 0.885, 0.32, 1.275)')) 41 | ]) 42 | ] 43 | }) 44 | export class PlaygroundComponent { 45 | // clock = Observable.interval(1000).do(_=>console.log('observable created')); 46 | signal: string; 47 | isVisible: boolean = true; 48 | birthday = new Date(); 49 | pi: number = 3.1415927; 50 | a: number = 5.03; 51 | b: number = 0.56; 52 | myNum: number = 0.1415927; 53 | object: Object = { 54 | foo: 'bar', 55 | baz: 'qux', 56 | nested: { 57 | xyz: 3, 58 | numbers: [1, 2, 3, 4, 5] 59 | } 60 | }; 61 | constructor() { } 62 | 63 | onGo(){ 64 | this.signal = 'go'; 65 | } 66 | onStop(){ 67 | this.signal = 'stop'; 68 | } 69 | 70 | toggle(){ 71 | this.isVisible = !this.isVisible; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/core/auth.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, Inject } from '@angular/core'; 2 | import { Http, Headers, Response } from '@angular/http'; 3 | 4 | import { Store } from '@ngrx/store'; 5 | import { Observable } from 'rxjs/Observable'; 6 | 7 | import { AppState, Auth } from '../domain/state'; 8 | import { UserService } from './user.service'; 9 | import { Router } from '@angular/router'; 10 | import { 11 | LOGIN, 12 | LOGIN_FAILED_NOT_EXISTED, 13 | LOGIN_FAILED_NOT_MATCH, 14 | LOGOUT, 15 | REGISTER, 16 | REGISTER_FAILED_EXISTED 17 | } from '../actions/auth.action' 18 | 19 | @Injectable() 20 | export class AuthService { 21 | 22 | constructor( 23 | private http: Http, 24 | private userService: UserService, 25 | private store$: Store, 26 | private router: Router) { 27 | } 28 | getAuth(): Observable { 29 | return this.store$.select(appState => appState.auth); 30 | } 31 | unAuth(): void { 32 | this.store$.dispatch({type: LOGOUT}); 33 | } 34 | register(username: string, password: string): void { 35 | let toAddUser = { 36 | username: username, 37 | password: password 38 | }; 39 | this.userService 40 | .findUser(username) 41 | .subscribe(user => { 42 | if(user != null) 43 | this.store$.dispatch({type: REGISTER_FAILED_EXISTED}); 44 | else 45 | this.store$.dispatch({type: REGISTER, payload: { 46 | user: toAddUser, 47 | hasError: false, 48 | errMsg: null, 49 | redirectUrl: null 50 | }}); 51 | }); 52 | } 53 | loginWithCredentials(username: string, password: string): void { 54 | this.userService 55 | .findUser(username) 56 | .subscribe(user => { 57 | if (null === user){ 58 | this.store$.dispatch({type: LOGIN_FAILED_NOT_EXISTED}); 59 | } 60 | else if(password !== user.password) { 61 | this.store$.dispatch({type: LOGIN_FAILED_NOT_MATCH}); 62 | } 63 | else{ 64 | this.store$.dispatch({type: LOGIN, payload: { 65 | user: user, 66 | hasError: false, 67 | errMsg: null, 68 | redirectUrl: null 69 | }}); 70 | this.router.navigate(['todo']); 71 | } 72 | }); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/login/login.component.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Component, 3 | Inject, 4 | trigger, 5 | state, 6 | style, 7 | transition, 8 | animate, 9 | OnDestroy 10 | } from '@angular/core'; 11 | 12 | import { MdDialog } from '@angular/material'; 13 | import { Auth, Image } from '../domain/entities'; 14 | import { RegisterDialogComponent } from './register-dialog.component'; 15 | import { AuthService } from '../core/auth.service'; 16 | import { BingImageService } from './bing-image.service'; 17 | import { Subscription } from 'rxjs/Subscription'; 18 | 19 | @Component({ 20 | selector: 'app-login', 21 | templateUrl: './login.component.html', 22 | styleUrls: ['./login.component.css'], 23 | animations: [ 24 | trigger('loginState', [ 25 | state('inactive', style({ 26 | transform: 'scale(1)' 27 | })), 28 | state('active', style({ 29 | transform: 'scale(1.1)' 30 | })), 31 | transition('inactive => active', animate('100ms ease-in')), 32 | transition('active => inactive', animate('100ms ease-out')) 33 | ]) 34 | ] 35 | }) 36 | export class LoginComponent implements OnDestroy{ 37 | 38 | username = ''; 39 | password = ''; 40 | slides: Image[] = []; 41 | photo = '/assets/login_default_bg.jpg'; 42 | loginBtnState: string = 'inactive'; 43 | subscription: Subscription; 44 | 45 | constructor( 46 | private authService: AuthService, 47 | private bingService: BingImageService, 48 | private dialog: MdDialog) { 49 | this.subscription = this.bingService.getImageUrl() 50 | .subscribe((images: Image[]) => { 51 | this.slides = [...images]; 52 | this.rotateImages(this.slides); 53 | }); 54 | } 55 | ngOnDestroy(){ 56 | if(this.subscription !== undefined) 57 | this.subscription.unsubscribe(); 58 | } 59 | onSubmit(){ 60 | this.authService 61 | .loginWithCredentials(this.username, this.password); 62 | } 63 | rotateImages(arr: Image[]){ 64 | const length = arr.length 65 | let i = 0; 66 | setInterval(() => { 67 | i = (i + 1) % length; 68 | this.photo = this.slides[i].contentUrl; 69 | }, 4000); 70 | } 71 | toggleLoginState(state: boolean){ 72 | this.loginBtnState = state ? 'active' : 'inactive'; 73 | } 74 | register($event: MouseEvent){ 75 | let pDialog = this.dialog.open(RegisterDialogComponent, { 76 | width: '350px' 77 | }); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/login/register-dialog.component.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Component, 3 | ViewChild, 4 | HostListener, 5 | OnInit, 6 | Inject 7 | } from '@angular/core'; 8 | 9 | import { Router } from '@angular/router'; 10 | import { 11 | FormGroup, 12 | Validators, 13 | FormControl, 14 | FormBuilder 15 | } from '@angular/forms'; 16 | import { MdDialog } from '@angular/material'; 17 | 18 | import { AuthService } from '../core/auth.service'; 19 | 20 | @Component({ 21 | selector: 'app-register-dialog', 22 | templateUrl: 'register-dialog.component.html', 23 | styleUrls: ['register-dialog.component.css'] 24 | }) 25 | export class RegisterDialogComponent{ 26 | @ViewChild('firstElement') private inputElement: HTMLInputElement; 27 | public form: FormGroup; 28 | public processingRegister = false; 29 | public statusMessage; 30 | 31 | constructor( 32 | private dialog: MdDialog, 33 | private fb: FormBuilder, 34 | private router: Router, 35 | private authService: AuthService) { 36 | this.form = fb.group({ 37 | 'username': new FormControl('', Validators.required), 38 | 'passwords': fb.group({ 39 | 'password': new FormControl('', Validators.required), 40 | 'repeatPassword': new FormControl('', Validators.required) 41 | },{validator: this.passwordMatchValidator}) 42 | }); 43 | } 44 | 45 | passwordMatchValidator(group: FormGroup){ 46 | let password = group.get('password').value; 47 | let confirm = group.get('repeatPassword').value; 48 | 49 | // Don't kick in until user touches both fields 50 | if (password.pristine || confirm.pristine) { 51 | return null; 52 | } 53 | if(password===confirm) { 54 | return null; 55 | } 56 | return {'mismatch': true}; 57 | } 58 | 59 | public register() { 60 | this.processingRegister = true; 61 | this.statusMessage = 'processing your registration ...'; 62 | 63 | this.authService 64 | .register( 65 | this.form.get('username').value, 66 | this.form.get('passwords').get('password').value); 67 | this.processingRegister = false; 68 | this.statusMessage = 'you are registered and will be signed in ...'; 69 | setTimeout( () => { 70 | this.dialog.closeAll() 71 | this.router.navigate(['todo']); 72 | }, 500); 73 | } 74 | 75 | @HostListener('keydown.esc') 76 | public onEsc(): void { 77 | this.dialog.closeAll(); 78 | } 79 | 80 | get ifShowStatusBar(): boolean { 81 | return this.statusMessage!==null ? true: false; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /angular/ng-tut/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/set'; 35 | 36 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 37 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 38 | 39 | /** IE10 and IE11 requires the following to support `@angular/animation`. */ 40 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 41 | 42 | 43 | /** Evergreen browsers require these. **/ 44 | import 'core-js/es6/reflect'; 45 | import 'core-js/es7/reflect'; 46 | 47 | 48 | /** ALL Firefox browsers require the following to support `@angular/animation`. **/ 49 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 50 | 51 | 52 | 53 | /*************************************************************************************************** 54 | * Zone JS is required by Angular itself. 55 | */ 56 | import 'zone.js/dist/zone'; // Included with Angular CLI. 57 | 58 | 59 | 60 | /*************************************************************************************************** 61 | * APPLICATION IMPORTS 62 | */ 63 | 64 | /** 65 | * Date, currency, decimal and percent pipes. 66 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10 67 | */ 68 | // import 'intl'; // Run `npm install --save intl`. 69 | -------------------------------------------------------------------------------- /angular/pragmatic/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/set'; 35 | 36 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 37 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 38 | 39 | /** IE10 and IE11 requires the following to support `@angular/animation`. */ 40 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 41 | 42 | 43 | /** Evergreen browsers require these. **/ 44 | import 'core-js/es6/reflect'; 45 | import 'core-js/es7/reflect'; 46 | 47 | 48 | /** ALL Firefox browsers require the following to support `@angular/animation`. **/ 49 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 50 | 51 | 52 | 53 | /*************************************************************************************************** 54 | * Zone JS is required by Angular itself. 55 | */ 56 | import 'zone.js/dist/zone'; // Included with Angular CLI. 57 | 58 | 59 | 60 | /*************************************************************************************************** 61 | * APPLICATION IMPORTS 62 | */ 63 | 64 | /** 65 | * Date, currency, decimal and percent pipes. 66 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10 67 | */ 68 | // import 'intl'; // Run `npm install --save intl`. 69 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/src/polyfills.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * This file includes polyfills needed by Angular and is loaded before the app. 3 | * You can add your own extra polyfills to this file. 4 | * 5 | * This file is divided into 2 sections: 6 | * 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers. 7 | * 2. Application imports. Files imported after ZoneJS that should be loaded before your main 8 | * file. 9 | * 10 | * The current setup is for so-called "evergreen" browsers; the last versions of browsers that 11 | * automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera), 12 | * Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile. 13 | * 14 | * Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html 15 | */ 16 | 17 | /*************************************************************************************************** 18 | * BROWSER POLYFILLS 19 | */ 20 | 21 | /** IE9, IE10 and IE11 requires all of the following polyfills. **/ 22 | // import 'core-js/es6/symbol'; 23 | // import 'core-js/es6/object'; 24 | // import 'core-js/es6/function'; 25 | // import 'core-js/es6/parse-int'; 26 | // import 'core-js/es6/parse-float'; 27 | // import 'core-js/es6/number'; 28 | // import 'core-js/es6/math'; 29 | // import 'core-js/es6/string'; 30 | // import 'core-js/es6/date'; 31 | // import 'core-js/es6/array'; 32 | // import 'core-js/es6/regexp'; 33 | // import 'core-js/es6/map'; 34 | // import 'core-js/es6/set'; 35 | 36 | /** IE10 and IE11 requires the following for NgClass support on SVG elements */ 37 | // import 'classlist.js'; // Run `npm install --save classlist.js`. 38 | 39 | /** IE10 and IE11 requires the following to support `@angular/animation`. */ 40 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 41 | 42 | 43 | /** Evergreen browsers require these. **/ 44 | import 'core-js/es6/reflect'; 45 | import 'core-js/es7/reflect'; 46 | 47 | 48 | /** ALL Firefox browsers require the following to support `@angular/animation`. **/ 49 | // import 'web-animations-js'; // Run `npm install --save web-animations-js`. 50 | 51 | 52 | 53 | /*************************************************************************************************** 54 | * Zone JS is required by Angular itself. 55 | */ 56 | import 'zone.js/dist/zone'; // Included with Angular CLI. 57 | 58 | 59 | 60 | /*************************************************************************************************** 61 | * APPLICATION IMPORTS 62 | */ 63 | 64 | /** 65 | * Date, currency, decimal and percent pipes. 66 | * Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10 67 | */ 68 | // import 'intl'; // Run `npm install --save intl`. 69 | -------------------------------------------------------------------------------- /angular/pragmatic/src/app/new-in-ng4/reactive/reactive.component.ts: -------------------------------------------------------------------------------- 1 | import { 2 | Component, 3 | OnInit 4 | } from '@angular/core'; 5 | import { 6 | FormGroup, 7 | FormBuilder, 8 | FormControl, 9 | Validators 10 | } from '@angular/forms'; 11 | import { BirthDay, AgeUnit, AppState, User } from '../../domain/entities.interface'; 12 | import { Store } from '@ngrx/store'; 13 | import { Observable } from 'rxjs/Observable'; 14 | import { Subscription } from 'rxjs/Subscription'; 15 | import 'rxjs/add/observable/combineLatest'; 16 | import 'rxjs/add/operator/debounceTime'; 17 | import 'rxjs/add/operator/distinctUntilChanged'; 18 | import * as moment from 'moment/moment'; 19 | 20 | @Component({ 21 | selector: 'app-reactive', 22 | templateUrl: './reactive.component.html', 23 | styleUrls: ['./reactive.component.scss'] 24 | }) 25 | export class ReactiveComponent implements OnInit { 26 | form: FormGroup; 27 | computed$: Observable; 28 | ageSub: Subscription; 29 | dateOfBirth$: Observable; 30 | dateOfBirthSub: Subscription; 31 | constructor( 32 | private fb: FormBuilder, 33 | private store$: Store) { } 34 | 35 | ngOnInit() { 36 | this.form = this.fb.group({ 37 | age: ['', Validators.required], 38 | ageUnit: ['', Validators.required], 39 | dateOfBirth: ['', Validators.compose([Validators.required, this.validateDate])] 40 | }); 41 | 42 | const initialAge = 33; 43 | const initialAgeUnit = AgeUnit.Year; 44 | this.form.controls['age'].setValue(initialAge); 45 | this.form.controls['ageUnit'].setValue(initialAgeUnit); 46 | 47 | const age$ = this.form.controls['age'].valueChanges 48 | .debounceTime(500) 49 | .distinctUntilChanged() 50 | .startWith(initialAge); 51 | 52 | const ageUnit$ = this.form.controls['ageUnit'].valueChanges 53 | .distinctUntilChanged() 54 | .startWith(initialAgeUnit); 55 | 56 | this.computed$ = Observable.combineLatest(age$, ageUnit$, (a, u)=>{ 57 | if(a === undefined || a <= 0 ) return initialAge; 58 | switch (parseInt(u)) { 59 | case AgeUnit.Day.valueOf(): 60 | return a; 61 | case AgeUnit.Month.valueOf(): 62 | return a * 30; 63 | case AgeUnit.Year.valueOf(): 64 | default: 65 | return a * 365; 66 | } 67 | }) 68 | .map(a => { 69 | const date = moment().subtract(a, 'days').format('YYYY-MM-DD'); 70 | return date; 71 | }); 72 | } 73 | 74 | validateDate(c: FormControl): {[key: string]: any}{ 75 | const result = moment(c.value).isValid 76 | && moment(c.value).isBefore() 77 | && moment(c.value).year()> 1900; 78 | return { 79 | "valid": result 80 | } 81 | } 82 | 83 | onSubmit() { 84 | if(!this.form.valid) return; 85 | const patient = { 86 | name: this.form.controls['name'].value, 87 | gender: this.form.controls['gender'].value, 88 | bloodType: this.form.controls['bloodType'].value, 89 | dateOfBirth: this.form.controls['dateOfBirth'].value, 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /angular2/playground/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "class-name": true, 7 | "comment-format": [ 8 | true, 9 | "check-space" 10 | ], 11 | "curly": true, 12 | "eofline": true, 13 | "forin": true, 14 | "indent": [ 15 | true, 16 | "spaces" 17 | ], 18 | "label-position": true, 19 | "label-undefined": true, 20 | "max-line-length": [ 21 | true, 22 | 140 23 | ], 24 | "member-access": false, 25 | "member-ordering": [ 26 | true, 27 | "static-before-instance", 28 | "variables-before-functions" 29 | ], 30 | "no-arg": true, 31 | "no-bitwise": true, 32 | "no-console": [ 33 | true, 34 | "debug", 35 | "info", 36 | "time", 37 | "timeEnd", 38 | "trace" 39 | ], 40 | "no-construct": true, 41 | "no-debugger": true, 42 | "no-duplicate-key": true, 43 | "no-duplicate-variable": true, 44 | "no-empty": false, 45 | "no-eval": true, 46 | "no-inferrable-types": true, 47 | "no-shadowed-variable": true, 48 | "no-string-literal": false, 49 | "no-switch-case-fall-through": true, 50 | "no-trailing-whitespace": true, 51 | "no-unused-expression": true, 52 | "no-unused-variable": true, 53 | "no-unreachable": true, 54 | "no-use-before-declare": true, 55 | "no-var-keyword": true, 56 | "object-literal-sort-keys": false, 57 | "one-line": [ 58 | true, 59 | "check-open-brace", 60 | "check-catch", 61 | "check-else", 62 | "check-whitespace" 63 | ], 64 | "quotemark": [ 65 | true, 66 | "single" 67 | ], 68 | "radix": true, 69 | "semicolon": [ 70 | "always" 71 | ], 72 | "triple-equals": [ 73 | true, 74 | "allow-null-check" 75 | ], 76 | "typedef-whitespace": [ 77 | true, 78 | { 79 | "call-signature": "nospace", 80 | "index-signature": "nospace", 81 | "parameter": "nospace", 82 | "property-declaration": "nospace", 83 | "variable-declaration": "nospace" 84 | } 85 | ], 86 | "variable-name": false, 87 | "whitespace": [ 88 | true, 89 | "check-branch", 90 | "check-decl", 91 | "check-operator", 92 | "check-separator", 93 | "check-type" 94 | ], 95 | 96 | "directive-selector-prefix": [true, "app"], 97 | "component-selector-prefix": [true, "app"], 98 | "directive-selector-name": [true, "camelCase"], 99 | "component-selector-name": [true, "kebab-case"], 100 | "directive-selector-type": [true, "attribute"], 101 | "component-selector-type": [true, "element"], 102 | "use-input-property-decorator": true, 103 | "use-output-property-decorator": true, 104 | "use-host-property-decorator": true, 105 | "no-input-rename": true, 106 | "no-output-rename": true, 107 | "use-life-cycle-interface": true, 108 | "use-pipe-transform-interface": true, 109 | "component-class-suffix": true, 110 | "directive-class-suffix": true, 111 | "templates-use-public": true, 112 | "invoke-injectable": true 113 | } 114 | } 115 | -------------------------------------------------------------------------------- /angular2/ng2-tut/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "callable-types": true, 7 | "class-name": true, 8 | "comment-format": [ 9 | true, 10 | "check-space" 11 | ], 12 | "curly": true, 13 | "eofline": true, 14 | "forin": true, 15 | "import-blacklist": [true, "rxjs"], 16 | "import-spacing": true, 17 | "indent": [ 18 | true, 19 | "spaces" 20 | ], 21 | "interface-over-type-literal": true, 22 | "label-position": true, 23 | "max-line-length": [ 24 | true, 25 | 140 26 | ], 27 | "member-access": false, 28 | "member-ordering": [ 29 | true, 30 | "static-before-instance", 31 | "variables-before-functions" 32 | ], 33 | "no-arg": true, 34 | "no-bitwise": true, 35 | "no-console": [ 36 | true, 37 | "debug", 38 | "info", 39 | "time", 40 | "timeEnd", 41 | "trace" 42 | ], 43 | "no-construct": true, 44 | "no-debugger": true, 45 | "no-duplicate-variable": true, 46 | "no-empty": false, 47 | "no-empty-interface": true, 48 | "no-eval": true, 49 | "no-inferrable-types": true, 50 | "no-shadowed-variable": true, 51 | "no-string-literal": false, 52 | "no-string-throw": true, 53 | "no-switch-case-fall-through": true, 54 | "no-trailing-whitespace": true, 55 | "no-unused-expression": true, 56 | "no-use-before-declare": true, 57 | "no-var-keyword": true, 58 | "object-literal-sort-keys": false, 59 | "one-line": [ 60 | true, 61 | "check-open-brace", 62 | "check-catch", 63 | "check-else", 64 | "check-whitespace" 65 | ], 66 | "prefer-const": true, 67 | "quotemark": [ 68 | true, 69 | "single" 70 | ], 71 | "radix": true, 72 | "semicolon": [ 73 | "always" 74 | ], 75 | "triple-equals": [ 76 | true, 77 | "allow-null-check" 78 | ], 79 | "typedef-whitespace": [ 80 | true, 81 | { 82 | "call-signature": "nospace", 83 | "index-signature": "nospace", 84 | "parameter": "nospace", 85 | "property-declaration": "nospace", 86 | "variable-declaration": "nospace" 87 | } 88 | ], 89 | "typeof-compare": true, 90 | "unified-signatures": true, 91 | "variable-name": false, 92 | "whitespace": [ 93 | true, 94 | "check-branch", 95 | "check-decl", 96 | "check-operator", 97 | "check-separator", 98 | "check-type" 99 | ], 100 | 101 | "directive-selector": [true, "attribute", "app", "camelCase"], 102 | "component-selector": [true, "element", "app", "kebab-case"], 103 | "use-input-property-decorator": true, 104 | "use-output-property-decorator": true, 105 | "use-host-property-decorator": true, 106 | "no-input-rename": true, 107 | "no-output-rename": true, 108 | "use-life-cycle-interface": true, 109 | "use-pipe-transform-interface": true, 110 | "component-class-suffix": true, 111 | "directive-class-suffix": true, 112 | "no-access-missing-member": true, 113 | "templates-use-public": true, 114 | "invoke-injectable": true 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /angular/ng-tut/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "callable-types": true, 7 | "class-name": true, 8 | "comment-format": [ 9 | true, 10 | "check-space" 11 | ], 12 | "curly": true, 13 | "eofline": true, 14 | "forin": true, 15 | "import-blacklist": [true, "rxjs"], 16 | "import-spacing": true, 17 | "indent": [ 18 | true, 19 | "spaces" 20 | ], 21 | "interface-over-type-literal": true, 22 | "label-position": true, 23 | "max-line-length": [ 24 | true, 25 | 140 26 | ], 27 | "member-access": false, 28 | "member-ordering": [ 29 | true, 30 | "static-before-instance", 31 | "variables-before-functions" 32 | ], 33 | "no-arg": true, 34 | "no-bitwise": true, 35 | "no-console": [ 36 | true, 37 | "debug", 38 | "info", 39 | "time", 40 | "timeEnd", 41 | "trace" 42 | ], 43 | "no-construct": true, 44 | "no-debugger": true, 45 | "no-duplicate-variable": true, 46 | "no-empty": false, 47 | "no-empty-interface": true, 48 | "no-eval": true, 49 | "no-inferrable-types": [true, "ignore-params"], 50 | "no-shadowed-variable": true, 51 | "no-string-literal": false, 52 | "no-string-throw": true, 53 | "no-switch-case-fall-through": true, 54 | "no-trailing-whitespace": true, 55 | "no-unused-expression": true, 56 | "no-use-before-declare": true, 57 | "no-var-keyword": true, 58 | "object-literal-sort-keys": false, 59 | "one-line": [ 60 | true, 61 | "check-open-brace", 62 | "check-catch", 63 | "check-else", 64 | "check-whitespace" 65 | ], 66 | "prefer-const": true, 67 | "quotemark": [ 68 | true, 69 | "single" 70 | ], 71 | "radix": true, 72 | "semicolon": [ 73 | "always" 74 | ], 75 | "triple-equals": [ 76 | true, 77 | "allow-null-check" 78 | ], 79 | "typedef-whitespace": [ 80 | true, 81 | { 82 | "call-signature": "nospace", 83 | "index-signature": "nospace", 84 | "parameter": "nospace", 85 | "property-declaration": "nospace", 86 | "variable-declaration": "nospace" 87 | } 88 | ], 89 | "typeof-compare": true, 90 | "unified-signatures": true, 91 | "variable-name": false, 92 | "whitespace": [ 93 | true, 94 | "check-branch", 95 | "check-decl", 96 | "check-operator", 97 | "check-separator", 98 | "check-type" 99 | ], 100 | 101 | "directive-selector": [true, "attribute", "app", "camelCase"], 102 | "component-selector": [true, "element", "app", "kebab-case"], 103 | "use-input-property-decorator": true, 104 | "use-output-property-decorator": true, 105 | "use-host-property-decorator": true, 106 | "no-input-rename": true, 107 | "no-output-rename": true, 108 | "use-life-cycle-interface": true, 109 | "use-pipe-transform-interface": true, 110 | "component-class-suffix": true, 111 | "directive-class-suffix": true, 112 | "no-access-missing-member": true, 113 | "templates-use-public": true, 114 | "invoke-injectable": true 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /angular/pragmatic/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "callable-types": true, 7 | "class-name": true, 8 | "comment-format": [ 9 | true, 10 | "check-space" 11 | ], 12 | "curly": true, 13 | "eofline": true, 14 | "forin": true, 15 | "import-blacklist": [true, "rxjs"], 16 | "import-spacing": true, 17 | "indent": [ 18 | true, 19 | "spaces" 20 | ], 21 | "interface-over-type-literal": true, 22 | "label-position": true, 23 | "max-line-length": [ 24 | true, 25 | 140 26 | ], 27 | "member-access": false, 28 | "member-ordering": [ 29 | true, 30 | "static-before-instance", 31 | "variables-before-functions" 32 | ], 33 | "no-arg": true, 34 | "no-bitwise": true, 35 | "no-console": [ 36 | true, 37 | "debug", 38 | "info", 39 | "time", 40 | "timeEnd", 41 | "trace" 42 | ], 43 | "no-construct": true, 44 | "no-debugger": true, 45 | "no-duplicate-variable": true, 46 | "no-empty": false, 47 | "no-empty-interface": true, 48 | "no-eval": true, 49 | "no-inferrable-types": [true, "ignore-params"], 50 | "no-shadowed-variable": true, 51 | "no-string-literal": false, 52 | "no-string-throw": true, 53 | "no-switch-case-fall-through": true, 54 | "no-trailing-whitespace": true, 55 | "no-unused-expression": true, 56 | "no-use-before-declare": true, 57 | "no-var-keyword": true, 58 | "object-literal-sort-keys": false, 59 | "one-line": [ 60 | true, 61 | "check-open-brace", 62 | "check-catch", 63 | "check-else", 64 | "check-whitespace" 65 | ], 66 | "prefer-const": true, 67 | "quotemark": [ 68 | true, 69 | "single" 70 | ], 71 | "radix": true, 72 | "semicolon": [ 73 | "always" 74 | ], 75 | "triple-equals": [ 76 | true, 77 | "allow-null-check" 78 | ], 79 | "typedef-whitespace": [ 80 | true, 81 | { 82 | "call-signature": "nospace", 83 | "index-signature": "nospace", 84 | "parameter": "nospace", 85 | "property-declaration": "nospace", 86 | "variable-declaration": "nospace" 87 | } 88 | ], 89 | "typeof-compare": true, 90 | "unified-signatures": true, 91 | "variable-name": false, 92 | "whitespace": [ 93 | true, 94 | "check-branch", 95 | "check-decl", 96 | "check-operator", 97 | "check-separator", 98 | "check-type" 99 | ], 100 | 101 | "directive-selector": [true, "attribute", "app", "camelCase"], 102 | "component-selector": [true, "element", "app", "kebab-case"], 103 | "use-input-property-decorator": true, 104 | "use-output-property-decorator": true, 105 | "use-host-property-decorator": true, 106 | "no-input-rename": true, 107 | "no-output-rename": true, 108 | "use-life-cycle-interface": true, 109 | "use-pipe-transform-interface": true, 110 | "component-class-suffix": true, 111 | "directive-class-suffix": true, 112 | "no-access-missing-member": true, 113 | "templates-use-public": true, 114 | "invoke-injectable": true 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /angular/from0to1/chap01/hello-angular/tslint.json: -------------------------------------------------------------------------------- 1 | { 2 | "rulesDirectory": [ 3 | "node_modules/codelyzer" 4 | ], 5 | "rules": { 6 | "callable-types": true, 7 | "class-name": true, 8 | "comment-format": [ 9 | true, 10 | "check-space" 11 | ], 12 | "curly": true, 13 | "eofline": true, 14 | "forin": true, 15 | "import-blacklist": [true, "rxjs"], 16 | "import-spacing": true, 17 | "indent": [ 18 | true, 19 | "spaces" 20 | ], 21 | "interface-over-type-literal": true, 22 | "label-position": true, 23 | "max-line-length": [ 24 | true, 25 | 140 26 | ], 27 | "member-access": false, 28 | "member-ordering": [ 29 | true, 30 | "static-before-instance", 31 | "variables-before-functions" 32 | ], 33 | "no-arg": true, 34 | "no-bitwise": true, 35 | "no-console": [ 36 | true, 37 | "debug", 38 | "info", 39 | "time", 40 | "timeEnd", 41 | "trace" 42 | ], 43 | "no-construct": true, 44 | "no-debugger": true, 45 | "no-duplicate-variable": true, 46 | "no-empty": false, 47 | "no-empty-interface": true, 48 | "no-eval": true, 49 | "no-inferrable-types": [true, "ignore-params"], 50 | "no-shadowed-variable": true, 51 | "no-string-literal": false, 52 | "no-string-throw": true, 53 | "no-switch-case-fall-through": true, 54 | "no-trailing-whitespace": true, 55 | "no-unused-expression": true, 56 | "no-use-before-declare": true, 57 | "no-var-keyword": true, 58 | "object-literal-sort-keys": false, 59 | "one-line": [ 60 | true, 61 | "check-open-brace", 62 | "check-catch", 63 | "check-else", 64 | "check-whitespace" 65 | ], 66 | "prefer-const": true, 67 | "quotemark": [ 68 | true, 69 | "single" 70 | ], 71 | "radix": true, 72 | "semicolon": [ 73 | "always" 74 | ], 75 | "triple-equals": [ 76 | true, 77 | "allow-null-check" 78 | ], 79 | "typedef-whitespace": [ 80 | true, 81 | { 82 | "call-signature": "nospace", 83 | "index-signature": "nospace", 84 | "parameter": "nospace", 85 | "property-declaration": "nospace", 86 | "variable-declaration": "nospace" 87 | } 88 | ], 89 | "typeof-compare": true, 90 | "unified-signatures": true, 91 | "variable-name": false, 92 | "whitespace": [ 93 | true, 94 | "check-branch", 95 | "check-decl", 96 | "check-operator", 97 | "check-separator", 98 | "check-type" 99 | ], 100 | 101 | "directive-selector": [true, "attribute", "app", "camelCase"], 102 | "component-selector": [true, "element", "app", "kebab-case"], 103 | "use-input-property-decorator": true, 104 | "use-output-property-decorator": true, 105 | "use-host-property-decorator": true, 106 | "no-input-rename": true, 107 | "no-output-rename": true, 108 | "use-life-cycle-interface": true, 109 | "use-pipe-transform-interface": true, 110 | "component-class-suffix": true, 111 | "directive-class-suffix": true, 112 | "no-access-missing-member": true, 113 | "templates-use-public": true, 114 | "invoke-injectable": true 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /angular2/ng2-tut/src/app/todo/todo.service.ts: -------------------------------------------------------------------------------- 1 | import { Injectable, Inject } from '@angular/core'; 2 | import { Http, Headers } from '@angular/http'; 3 | import { UUID } from 'angular2-uuid'; 4 | 5 | import { Observable } from 'rxjs/Observable'; 6 | import { Store } from '@ngrx/store'; 7 | import { Router } from '@angular/router'; 8 | import { AppState, Todo, Auth } from '../domain/state'; 9 | import { 10 | ADD_TODO, 11 | TOGGLE_TODO, 12 | REMOVE_TODO, 13 | TOGGLE_ALL, 14 | CLEAR_COMPLETED, 15 | FETCH_FROM_API 16 | } from '../actions/todo.action' 17 | 18 | @Injectable() 19 | export class TodoService { 20 | 21 | private api_url = 'http://localhost:3000/todos'; 22 | private headers = new Headers({'Content-Type': 'application/json'}); 23 | private auth$: Observable; 24 | 25 | constructor( 26 | private http: Http, 27 | private router: Router, 28 | private store$: Store 29 | ) { 30 | this.auth$ = this.store$.select(appState => appState.auth) 31 | .filter(auth => auth.user !== null) 32 | .map(auth => auth.user.id); 33 | } 34 | 35 | // POST /todos 36 | addTodo(desc:string): void{ 37 | this.auth$.flatMap(userId => { 38 | let todoToAdd = { 39 | id: UUID.UUID(), 40 | desc: desc, 41 | completed: false, 42 | userId: userId 43 | }; 44 | return this.http 45 | .post(this.api_url, JSON.stringify(todoToAdd), {headers: this.headers}) 46 | .map(res => res.json() as Todo); 47 | }).subscribe(todo => { 48 | this.store$.dispatch({type: ADD_TODO, payload: todo}); 49 | }); 50 | } 51 | // It was PUT /todos/:id before 52 | // But we will use PATCH /todos/:id instead 53 | // Because we don't want to waste the bytes those don't change 54 | toggleTodo(todo: Todo): void { 55 | const url = `${this.api_url}/${todo.id}`; 56 | let updatedTodo = Object.assign({}, todo, {completed: !todo.completed}); 57 | this.http 58 | .patch(url, JSON.stringify({completed: !todo.completed}), {headers: this.headers}) 59 | .mapTo(updatedTodo) 60 | .subscribe(todo => { 61 | this.store$.dispatch({ 62 | type: TOGGLE_TODO, 63 | payload: updatedTodo 64 | }); 65 | }); 66 | } 67 | // DELETE /todos/:id 68 | removeTodo(todo: Todo): void { 69 | const url = `${this.api_url}/${todo.id}`; 70 | this.http 71 | .delete(url, {headers: this.headers}) 72 | .mapTo(Object.assign({}, todo)) 73 | .subscribe(todo => { 74 | this.store$.dispatch({ 75 | type: REMOVE_TODO, 76 | payload: todo 77 | }); 78 | }); 79 | } 80 | // GET /todos 81 | getTodos(): Observable { 82 | return this.auth$ 83 | .flatMap(userId => this.http.get(`${this.api_url}?userId=${userId}`)) 84 | .map(res => res.json() as Todo[]); 85 | } 86 | 87 | toggleAll(): void{ 88 | this.getTodos() 89 | .flatMap(todos => Observable.from(todos)) 90 | .flatMap(todo=> { 91 | const url = `${this.api_url}/${todo.id}`; 92 | let updatedTodo = Object.assign({}, todo, {completed: !todo.completed}); 93 | return this.http 94 | .patch(url, JSON.stringify({completed: !todo.completed}), {headers: this.headers}) 95 | }) 96 | .subscribe(()=>{ 97 | this.store$.dispatch({ 98 | type: TOGGLE_ALL 99 | }); 100 | }) 101 | } 102 | 103 | clearCompleted(): void { 104 | this.getTodos() 105 | .flatMap(todos => Observable.from(todos.filter(t => t.completed))) 106 | .flatMap(todo=> { 107 | const url = `${this.api_url}/${todo.id}`; 108 | return this.http 109 | .delete(url, {headers: this.headers}) 110 | }) 111 | .subscribe(()=>{ 112 | this.store$.dispatch({ 113 | type: CLEAR_COMPLETED 114 | }); 115 | }); 116 | } 117 | } 118 | --------------------------------------------------------------------------------