Enhance Web Development

Angular 2

 

Introduction to Components

Module Overview

What is a Component?

Creating the Component class

Defining the Metadata with a Decorator

Importing what we need

Bootstrapping our App Component

Sample Application Architecture

App

Component

Welcome

Component

Product List

Component

Product Detail

Component

Star

Component

index.html

Product Data

Service

What is a Component?

Component

Template

Class

Metadata

=

+

+

Properties

Methods

  • Code supporting the view
  • Created with Typescript
  • Properties: data
  • Methods: logic
  • View layout
  • Created with HTML
  • Includes binding and directives
  • Extra data for Angular
  • Defined with a decorator

Setting up Our Environment

npm

Node package manager

Command line utility

Installs libraries, packages and applications

https://www.npmjs.com/

Setting up an Angular 2 Application

  1. Create an application folder
  2. Add package definition and configuration files
  3. Install the packages
  4. Create the app's Angular Module
  5. Create the main.ts file
  6. Create the host Web page (index)

Setting up an Angular 2 Application

Manually perform each step

www.angular.io / Quick start

Download the results of these steps

https://github.com/angular/quickstart

Angular CLI

https://github.com/angular/angular-cli

Starter files

https://github.com/firehist/angular2-courses

 

 

 

Some useful tools

About Modules

Namespaces

Code organisation

Angular 1 Modules

TypeScript Modules

ES2015
Modules

Angular 2 Modules

ES 2015 Modules

 product.ts

export class Product {
}

 product.js

function Product() {
}

 product-list.ts

import { Product } from
'./product'

Export

Import

Angular Modules

Component

Root
Angular Module

Component

Component

Component

Feature
Angular Module

Component

Component

Component

Component

Shared
Angular Module

Component

Modules

ES Modules

Code files that import or export something

 

Organize our code files

Modularize our code

Promote code reuse

Angular Modules

Code files that organize the application into blocks of functionality

Organize our application

Modularize our application

Promote application boundaries

Web Browser

Web Server

URL Request (mysite.com)

Response

index.html

JavaScript

Summary

Selecting a Language

Selecting an Editor

Setting up an Angular 2 Application

About Modules

Sample Application Architecture

App

Component

Welcome

Component

User List

Component

User Detail

Component

Star

Component

index.html

User Data

Service

03 - Introduction to Components

By Benjamin LONGEARET

03 - Introduction to Components

  • 1,183