diff --git a/src/app/api.service.ts b/src/app/api.service.ts index 8f6852d..1ba388f 100644 --- a/src/app/api.service.ts +++ b/src/app/api.service.ts @@ -6,7 +6,7 @@ import { catchError, tap, map } from 'rxjs/operators'; const httpOptions = { headers: new HttpHeaders({'Content-Type': 'application/json'}) }; -const apiUrl = "/api"; +const apiUrl = '/api'; @Injectable({ providedIn: 'root' @@ -28,10 +28,10 @@ export class ApiService { } // return an observable with a user-facing error message return throwError('Something bad happened; please try again later.'); - }; + } private extractData(res: Response) { - let body = res; + const body = res; return body || { }; } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index bde3d27..60900e8 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -20,7 +20,7 @@ import { MatIconModule, MatButtonModule, MatCardModule, - MatFormFieldModule } from "@angular/material"; + MatFormFieldModule } from '@angular/material'; const appRoutes: Routes = [ { diff --git a/src/app/book-create/book-create.component.ts b/src/app/book-create/book-create.component.ts index b450ae8..dbd32b2 100644 --- a/src/app/book-create/book-create.component.ts +++ b/src/app/book-create/book-create.component.ts @@ -11,12 +11,12 @@ import { FormControl, FormGroupDirective, FormBuilder, FormGroup, NgForm, Valida export class BookCreateComponent implements OnInit { bookForm: FormGroup; - isbn:string=''; - title:string=''; - description:string=''; - author:string=''; - publisher:string=''; - published_year:string=''; + isbn = ''; + title = ''; + description = ''; + author = ''; + publisher = ''; + published_year = ''; constructor(private router: Router, private api: ApiService, private formBuilder: FormBuilder) { } @@ -31,10 +31,10 @@ export class BookCreateComponent implements OnInit { }); } - onFormSubmit(form:NgForm) { + onFormSubmit(form: NgForm) { this.api.postBook(form) .subscribe(res => { - let id = res['_id']; + const id = res['_id']; this.router.navigate(['/book-details', id]); }, (err) => { console.log(err); diff --git a/src/app/book-edit/book-edit.component.ts b/src/app/book-edit/book-edit.component.ts index 1e4e49b..9ab395b 100644 --- a/src/app/book-edit/book-edit.component.ts +++ b/src/app/book-edit/book-edit.component.ts @@ -11,13 +11,13 @@ import { FormControl, FormGroupDirective, FormBuilder, FormGroup, NgForm, Valida export class BookEditComponent implements OnInit { bookForm: FormGroup; - id:string = ''; - isbn:string = ''; - title:string = ''; - description:string = ''; - author:string = ''; - publisher:string = ''; - published_year:string = ''; + id = ''; + isbn = ''; + title = ''; + description = ''; + author = ''; + publisher = ''; + published_year = ''; constructor(private router: Router, private route: ActivatedRoute, private api: ApiService, private formBuilder: FormBuilder) { } @@ -47,10 +47,10 @@ export class BookEditComponent implements OnInit { }); } - onFormSubmit(form:NgForm) { + onFormSubmit(form: NgForm) { this.api.updateBook(this.id, form) .subscribe(res => { - let id = res['_id']; + const id = res['_id']; this.router.navigate(['/book-details', id]); }, (err) => { console.log(err); diff --git a/src/app/book/book.component.ts b/src/app/book/book.component.ts index a111abd..9d3c286 100644 --- a/src/app/book/book.component.ts +++ b/src/app/book/book.component.ts @@ -3,6 +3,20 @@ import { ApiService } from '../api.service'; import { DataSource } from '@angular/cdk/collections'; import { Observable } from 'rxjs'; +export class BookDataSource extends DataSource { + constructor(private api: ApiService) { + super(); + } + + connect() { + return this.api.getBooks(); + } + + disconnect() { + + } +} + @Component({ selector: 'app-book', templateUrl: './book.component.html', @@ -26,17 +40,3 @@ export class BookComponent implements OnInit { }); } } - -export class BookDataSource extends DataSource { - constructor(private api: ApiService) { - super() - } - - connect() { - return this.api.getBooks(); - } - - disconnect() { - - } -}