Answer the question
In order to leave comments, you need to log in
GET request in Postman gives status 200, but through the local server 304, how to fix it?
There are 2 TS files
categories-page.component.ts
import {Component, OnInit} from '@angular/core';
import {CategoriesService} from "../shared/servicis/categories.service";
import {Category} from "../shared/interfaces";
@Component({
selector: 'app-categories-page',
templateUrl: './categories-page.component.html',
styleUrls: ['./categories-page.component.css']
})
export class CategoriesPageComponent implements OnInit {
loading = false
categor: Category[] = []
constructor(private categoriesService: CategoriesService) {
}
ngOnInit() {
this.loading = true
this.categoriesService.fetch().subscribe(categories => {
this.loading = false
this.categor = categories
console.log('Categories', categories)
})
}
}
import {Injectable} from '@angular/core'
import {HttpClient} from '@angular/common/http'
import {Category} from '../interfaces'
import {Observable} from 'rxjs'
@Injectable({
providedIn: 'root'
})
export class CategoriesService {
constructor(private http: HttpClient) {
}
fetch(): Observable<Category[]> {
return this.http.get<Category[]>('/api/category')
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question