Professional Documents
Culture Documents
Marina Magdy
Agenda
"resolveJsonModule": true,
"esModuleInterop": true
}
Routing
Routing
● In a single-page app, you change what the user sees by showing or hiding
portions of the display that correspond to particular components, rather
than going out to the server to get a new page. As users perform
application tasks, they need to move between the different views that you
have defined.
● To handle the navigation from one view to the next, you use the Angular
Router. The Router enables navigation by interpreting a browser URL as an
instruction to change the view.
Routing
The advantages of an SPA are:
children: [
},
It takes as input an array of classes which it will add to the element it’s attached to
if it’s route is currently active
Material : https://angular.io/api/router/RouterLinkActive
Navigation : Parameterised Routes
Sometimes we need part of the path in one or more of our routes (the URLs) to
be a variable, a common example of this is an ID for example : /movie/1
We will learn to :
];
The path has a variable called id, we know it’s a variable since it
From html :
[routerLink]="[‘movie’, movie.id]”
From ts:
this.router.navigate(['movie', idValue]);
Navigation : Parameterised Routes
this.route.snapshot.params['id']
}
Dependency
Injection
Dependency Injection
By default the value is set to ‘root’. This translates to the root injector of the
application. Basically, setting the field to ‘root’ makes the service available
anywhere.
Observable
Behavior subject
In the service,
● In your service that calls apis import httpClient and create a new instance from
it in constructor
getList(): Observable<any> {
return this.http.get('API');
}
Subscribe
Example :
this.service.getData().subscribe(
data => { this.data = data },
error => { console.log('error: ', error)},
() => { console.log('complete ', "compelete"); });
Thank you
Lap
Products
Continuing on the previous task
Shirt Shoes
● Product images
● Product name
● Product category
● Product price [ 20 EGP]
● “Add to cart” button
Product card will be clickable to show detailed view for the item clicked
Products Products Register Login
● Products List :
https://60523dc8fb49dc00175b7d04.mockapi.io/
api/v1/products Products details data
● Product Details :
Add to cart
https://60523dc8fb49dc00175b7d04.mockapi.io/
api/v1/products/id
Products 5 Register Login
Cart
+ 1 - remove
+ 5 - remove