Learn Angular With Practical Example
Learn Angular With Practical Example
Practical Examples
MD SHAHIDULLA
Agenda
Why Angular 2 or 4? Dependency Injection
Setting up Angular 2 or 4 in Wrap up third party
Visual Studio services
Angular Architecture HTTP and Observables
Routing and Child Routing Observable vs Promise
RouterLink and Router.navigate Mapping HTTP Response
with Observable
Lazy Module Loading
Reactive/ModelDriven
Angular Services
Form and Validation
Why Angular 2 or 4?
Faster
Mobile support
o Visual Studio
o Visual Studio Code
o Eclipse
o WebStrom
o Atom
o Sublime Text etc.
Why Angular 2 or 4?
More language choices:
o TypeScript
Intelligence
Code navigation
Advanced refactoring
Strong Typing
Support ES 2015 (ES 6) features like classes, interface and inheritance
Module
o Step 1: Add base href at intex.html inside head section <base href=/>
o Step 2: Create route.ts at the root of the folder and import
RouterModule, Routes from @angular/router inside root route
o Step 3: Configure appRouting
o Step 4: Import appRouting in app.module.ts (App Module)
o Step 5: Add appRouting inside imports array of appModule
Child Routing: Same as Routing. Just need to call forChild
RouterLink and Router.navigate
The RouterLink and Router.navigate let you link to specific parts of
your app.
You can use [routerLink] in any html element.
o Step 2: Add the new route inside root route. For example,
{Path:blog,loadChildren:app/blog/blog.module#BlogModule}
o Step 3: Remove the respective module from app root module.
Angular Services
In Angular, a service is basically any set of functionality that we
want to be available to multiple components.
The following key steps need to be carried out when creating a
service:
o Step 1: Create a separate class which has the injectable decorator.
o Step 2: Register it with provider in app root module. Angular can inject it
into the constructor of any component or service, anywhere in the
application.
o Step 3: Inject where you want to use it inside constructor.
Wrap Up Third party Services
Steps to implement third party service:
o Step 1: Install third party service. For example,
npm install toastr save
o Step 2: Import the necessary files in index.html
o Step 3: Create a service to wrap up third party service methods.
o Step 4: Import the service in app module/feature module.
o Step 5: Register that service with provider.
o Step 6: Inject that service where we want to use.
HTTP and Observables
To call any external API, we need to use Angular HTTP library. We can
use Observables with HTTP.
Cllback ->Promises ->Observable