36
Presented by DEBBABI Nader Introduction To Angular 4 Training Sessions Organized by Club Jeunes Ingénieurs ISAMM

Introduction To Angular 4 - J2I

Embed Size (px)

Citation preview

Page 1: Introduction To Angular 4 - J2I

Presented by DEBBABI Nader

Introduction To Angular 4

Training Sessions Organized byClub Jeunes Ingénieurs ISAMM

Page 2: Introduction To Angular 4 - J2I

ANGULAROne framework.Web, Mobile & Desktop.

Page 3: Introduction To Angular 4 - J2I

Agenda

> What is Angular ?

> Motivation

> TypeScript ?

> Single Page Application (SPA)

> Development Environment Setup

> Hello World!

> Bootstrapping the app

> Building Blocks & Architecture

Page 4: Introduction To Angular 4 - J2I

What is Angular ?

Page 5: Introduction To Angular 4 - J2I

What is Angular ?

An Open-Source JavaScript Framework, used to build Single Page based Web Application (SPA),

Developed by Google,

Release date March 2017,

Current version 4.4.4 (stable).

Page 6: Introduction To Angular 4 - J2I

Motivation

Page 7: Introduction To Angular 4 - J2I

Motivation

> Speed & Performance,> Smaller application,> Modular application,> Cross-platform Web, Mobile & Desktop,> SPA,> RESTful API,> Uses TypeScript,> Rxjs API Integration,> & It has a huge community on GitHub.

Page 8: Introduction To Angular 4 - J2I

TypeScript ?

Page 9: Introduction To Angular 4 - J2I

TypeScript ?

Free & Open-Source programming language,

Developed & maintained by Microsoft,

A superset of JavaScript,

Full Object-Oriented Programming with features like classes, interfaces & modules…

Support for ECMAScript 5 and uses arrow function syntax,

Compiles to plain JavaScript.

Page 10: Introduction To Angular 4 - J2I

Single Page Application (SPA)

Page 11: Introduction To Angular 4 - J2I

Single Page Application ?

One and Only HTML page for the entire application,

Dynamically update the single page with new data if needed, as the user interacts with the app,

Show and Hide some components during the interaction process,

No reloading or refreshing during navigation,

More responsive & fluid app as a result,

Full separation between the presentation logic & business logic,

Asynchronous Requests (AJAX), JSON response & RESTful API.

Page 12: Introduction To Angular 4 - J2I

Traditional way

Page 13: Introduction To Angular 4 - J2I

Single Page Application

Page 14: Introduction To Angular 4 - J2I

ANGULAR for Client Web App

Page 15: Introduction To Angular 4 - J2I

ANGULAR for Client Web App

Page 16: Introduction To Angular 4 - J2I

Development EnvironmentSetup

Page 17: Introduction To Angular 4 - J2I

Development Environment Setup

Node.js is an open-source, cross-platform JavaScript run-time environment, we use it to:> Run a development server,> Use the npm tool.

npm is a Node.js Package Manager for JavaScript programming language,npm is automatically installed with Nodejs,

Page 18: Introduction To Angular 4 - J2I

Development Environment Setup

To develop the application using TypeScriptwe need to install the TypeScript packageusing the command,

Angular CLI (Command Line Interface) is a tool that allows us to create a project, generate it’s parts, build it and run it on the development server directly through the command line,

Page 19: Introduction To Angular 4 - J2I

Development Environment Setup

Visual Studio Code as a Text Editor,

Page 20: Introduction To Angular 4 - J2I

Hello World!!

Page 21: Introduction To Angular 4 - J2I

Hello World!!

> Go to workspace directory,

> Using Angular CLI ng new command create the Hello World application,

> Go to the Hello World directory,

> Run the application using another Angular CLI command ng serve,

Page 22: Introduction To Angular 4 - J2I

Basic Structure of ANGULAR Application

Page 23: Introduction To Angular 4 - J2I

Basic Structure of ANGULAR Application

.angular-cli.json , package.jsonand tsconfig.json are theresponsible files on the projectconfiguration, it’s dependencymanagement and it’s externalpackages.

Page 24: Introduction To Angular 4 - J2I

Basic Structure of ANGULAR Application

main.ts and index.html are theentry point to the application,

Since we are developing a SPAindex.html is the only HTMLpage in the whole project,

style.css is the style sheet forthe global app design.

Page 25: Introduction To Angular 4 - J2I

Basic Structure of ANGULAR Application

node_modules folder containsthe packages installed by thenpm tool,

app folder contains all the work,components, modules…

Page 26: Introduction To Angular 4 - J2I

Bootstrapping the app

Page 27: Introduction To Angular 4 - J2I

Bootstrapping the app

Page 28: Introduction To Angular 4 - J2I

Building Blocks

Page 29: Introduction To Angular 4 - J2I

Building Blocks

Every Angular app has at least one Module, the root module named AppModule,

An Angular app is a Modular app,

A module is a TypeScript class with the Decorator @NgModule,

Each module in the application has it’s own Components, Directives, Services… They should be declared in @NgModule decorator,

Modules can cooperate to achieve some app functionalities.

Page 30: Introduction To Angular 4 - J2I

Building Blocks

A Component controls a piece of screen called view,

This view is defined by the Template associated to the Component,

A Component handles the user interaction with the view (Template), passes data and properties to the view and updates it dynamically,

A Component is a TypeScript class with the Decorator @Component.

Page 31: Introduction To Angular 4 - J2I

Building Blocks

A Component view is defined by its associated Template,

A Template is bunch of HTML tags,

Along side with the HTML, a Template typically contains some particular expressions and syntaxwhich belong to Angular,

A Template may contain some Custom Tags, that represent another Component, the selectors.

Page 32: Introduction To Angular 4 - J2I

Building Blocks

A Module, a Component, a Directive or a Serviceare just TypeScript Classes until we tell Angular about the difference between them, and that is done by the Metadata,

We attach Metadata in TypeScript to a class by using Decorators, @NgModule, @Component, @Injectable…

Metadata tells Angular which Template belongs to which Component and which Component belongs to which Module…

Class + @Component + Metadata = A Component

Page 33: Introduction To Angular 4 - J2I

Building Blocks

Page 34: Introduction To Angular 4 - J2I

Building Blocks

A Directive is a TypeScript class with the Decorator @Directive,

Directives appear within HTML tag as attributes,

Two kind of directives: Structural & Attribute Directives,

Structural Directives change the layout by adding or removing Template elements,Example: *ngFor & *ngIf.

Attribute Directives change the appearance or the behavior of an existing Template element,Example: ngModel, ngStyle & ngClass.

Page 35: Introduction To Angular 4 - J2I

Building Blocks

A Service is a TypeScript class with the Decorator @Injectable,

A Service achieve some functionalities for the application such us fetching data from server, authentication…

This kind of functionalities should not be done in the Component,

A Component should only take care of rendering the Template (view).

Page 36: Introduction To Angular 4 - J2I

Thanks for your attention !!