Содержание
- 2. Wiki
- 3. Angular CLI Install Node.js and npm: https://nodejs.org/en/download/ Install the Angular CLI globally: npm install -g @angular/cli
- 4. Angular
- 5. Project folder structure tsconfig.json – TypeScripts https://www.typescriptlang.org/docs/handbook/tsconfig-json.html package.json – npm https://docs.npmjs.com/files/package.json .angular-cli.json – Angular CLI configuration
- 6. Project folder structure e2e – automated UI tests (Selenium/Protractor) src – our application sources node_modules –
- 7. NgModule main.ts – app entry point app.module.ts - main module @NgModule({ declarations: [ AppComponent ], imports:
- 8. Component @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { title = 'app
- 9. Data binding interpolation property binding event binding build-in directives is the interpolated image. is the property
- 10. Event binding Increment onIncrementClick() { this.visitors++; } html: component onIncrementClick(event: MouseEvent) { console.log(`x: ${event.x}, y: ${event.y}`);
- 11. Two-way binding NgModel - a built-in directive that makes two-way binding easy. It requires FormsModule. NgModel
- 12. Binding syntax: An overview
- 13. Binding targets
- 14. Basic Routing import { RouterModule, Routes } from '@angular/router'; ng g c product-list generate components: app.module:
- 15. Build-in attribute directives: NgFor & NgIf NgFor is a repeater directive — a way to present
- 16. Lifecycle Hooks
- 17. Component Interaction: @Input decorator ng g c product generate new component: move product HTML from product-list.component
- 18. Component Interaction: @Output decorator product.component.ts @Output() deleteRequest = new EventEmitter (); onDeleteClick() { this.deleteRequest.emit(this.product); } product.component.html
- 19. Pipes ng g pipe price generate pipe: built-in pipes: date, uppercase, lowercase, currency, percent template: {{product.price
- 20. Services ng g s products generate service: products.service.ts @Injectable() export class ProductsService { constructor() { }
- 21. Dependency Injection Angular has a Hierarchical Dependency Injection system. There is actually a tree of injectors
- 22. Http getProducts(): Observable { return this.http.get('http://localhost:54145/api/products') .map(res => res.json() as Product[]); } ngOnInit() { this.productsService.getProducts().subscribe( (products:
- 23. Http + AsyncPipe product-list.component.ts: products.service.ts: search(term: string): Observable { return this.http .post(`http://localhost:54145/api/products`, { name: term })
- 25. Скачать презентацию