Home Consuming a REST API using Angular Observable
Reply: 0

Consuming a REST API using Angular Observable

user1465
1#
user1465 Published in May 21, 2018, 12:34 pm

I recently created a rest API using flask , now when I tried to use it with my Angular web App , I am receiving these errors ( I Tried to follow the same steps mentioned in the official docs : https://angular.io/tutorial/toh-pt6 )

getBills(): void {
          this.BillService.getBills()
             .subscribe(bills => this.billData=bills);
      }
       }

the error is :

ERROR in ../src/app/Bills/add-new-bill.component.ts (61,31): Type '{} | BillModel[]' is not assignable to type 'BillModel[]'. Type '{} | BillModel[]' is not assignable to type 'BillModel[]'. Type '{}' is not assignable to type 'BillModel[]'. Property 'includes' is missing in type '{}'.

this is my bill.service code :

getBills() {
    return this.http.get<BillModel[]>('http://localhost:5000/bills/123')
        .pipe(
            catchError(this.handleError('getBills'))
        );
}

and this is the model Class for my bill object :

export class BillModel {
    Amount: number;
    Bill_id: number;
    CreatedAt: string;
    From: string;
    PaymentDate: string;
    PaymentStatus: boolean;
    To: string;
};

and it works perfectly but I want to work with the observable mechanism so would u please help or explain to me why I am getting that kind of error

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.366356 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO