My final GADs project is building an album store product page in angular. Just so you know the only thing I know about angular is that its a framework. I'm learning on the job though. Today's post is about the scanty knowledge I've gathered so far.
Service class
I created a service class today, but what is a service class?
A service in angular handles data allowing it to be shared among components.
Components shouldn't fetch or save data directly and they certainly shouldn't knowingly present fake data. They should focus on presenting data and delegate data access to a service.
Angular documentation
Command used to create a service class:
ng generate service product
Declaring public and private Class properties
Private properties
private _albumUrl = string;
Public properties
public name: string;
To access properties in a class you use this
keyword:
this.name
In the class when we refer to one of the members of the class we prepend
this.
. This denotes that itβs a member access.
Typescript handbook
Declaring Class Methods
getAlbum() { }
It is an interesting ride, is should probably find a crach course on Angular.
Adding a return type to a function.
getAlbum(id: number):Album{}
//Where Ablum is an interface
Observables
Observable are just things you wish to observe and take action on.
Angular and Observable by Bhatt Ami
getAlbum(id: number):Observable<Album> {}
Casting
Changing or converting types
That's it for day 75
Let's do this again tomorrow
Top comments (0)