jude jay

jude jay

  • NA
  • 17
  • 1.6k

Send Boolean to WEB API in Angular with checkbox

Feb 18 2021 6:57 PM
Hi,
I have an API i would like to get a subset of the data by setting a boolean on the form, checkbox would be ideal.
The API is the same one returns all the set, but has an extra true or false, works with swagger.
 
This is Angular 11. Not used any material or bootstrap yet.
Using a service to bring in the data from the API, can get list rendered of all values atm..
The base uRL is just that same with true added.
 
 SO FAR
 
HTML
    <input #sendBulletinCheckBox
    id="sendBulletinCheckBox"
    type="checkbox"
    [checked]="sendBulletin"
    (change)="onSendBulletinChanged(sendBulletinCheckBox.checked)" />
    
    TS Service function to get API data
    
  refreshList() {
       return this.httpClient.get<{ [key: string]: CustomerDetails  }>(this.baseURL ,
        {
          headers: new HttpHeaders({ 'Custom-Header': 'Hello'}),
          responseType:'json'
        }
        )
        .pipe(
          map(responseData =>
            {
          const contacts: CustomerDetails[]=[];
          for (const key in responseData){
            if (responseData.hasOwnProperty(key)){
              contacts.push({ ...responseData[key], Id: key});
            }
          }
          return contacts;
        }),
        catchError(errorRes => {
          return throwError(errorRes);
        })
        );

Answers (1)