This is my first contact with AngularJS. I would like to integrate the api with a front in Angular, my goal is just to return a list of data, making it as simple as possible is my goal.
CodePudding user response:
[link][1] Setup for server communication Before you can use HttpClient, you need to import the Angular HttpClientModule. Most apps do so in the root AppModule.
app/app.module.ts (excerpt)
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { HttpClientModule } from '@angular/common/http';
You can then inject the HttpClient service as a dependency of an application class, as shown in the following ConfigService example.
app/config/config.service.ts (excerpt)
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable()
export class ConfigService {
constructor(private http: HttpClient) { }
}
The HttpClient service makes use of observables for all transactions. You must import the RxJS observable and operator symbols that appear in the example snippets. These ConfigService imports are typical.
app/config/config.service.ts (RxJS imports)
content_copy
import { Observable, throwError } from 'rxjs';
import { catchError, retry } from 'rxjs/operators';