web-dave / angular_workshop

0 stars 0 forks source link

Create a Service #6

Open web-dave opened 4 months ago

web-dave commented 4 months ago
  1. Intall Backend and start it
    bookmonkey-api

Install

npm i bookmonkey-api -D

package.json

{
...
 "scripts": {
    ...
    "backend": "bookmonkey-api"
  },
...
}

run

npm run backend

Check http://localhost:4730

  1. Generate Service ng g s books/book

  2. Provide HttpClient in your App

    app.config.ts
export const appConfig: ApplicationConfig = {
  providers: [..., provideHttpClient()],
};

  1. Get HttpClient into the Service via DI
    book.service.ts
...
export class BookService {
 private http = inject(HttpClient);
}

  1. Implement first service method to get All books
    book.service.ts
...
  getAll() {
    return this.http.get<any>('http://localhost:4730/books');
  }

web-dave commented 4 months ago

NEXT