I develop a web API using .NET Core web API and then try to get data from it to my Angular11.
these are the codes shared.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { observable, Observable } from 'rxjs';
@Injectable({
providedIn: 'root'
})
export class SharedService {
readonly APIUrl = "http://localhost:5000/api";
readonly PhotoUrl = "http://localhost:5000/photos";
constructor(private http: HttpClient) { }
getSecList(): Observable<any[]> {
return this.http.get<any>(this.APIUrl + '/section');
}}
show-sec.component.ts
import { Component, OnInit } from '@angular/core';
import { SharedService } from './../../shared.service';
@Component({
selector: 'app-show-sec',
templateUrl: './show-sec.component.html',
styleUrls: ['./show-sec.component.css']
})
export class ShowSecComponent implements OnInit {
constructor(private service: SharedService) { }
SectionList: any = [];
ngOnInit(): void {
this.refreshSecList();
}
refreshSecList() {
this.service.getSecList().subscribe(data => {
this.SectionList = data;
console.log(this.SectionList);
});
}
}
but I can not get data from api it shows following error in console.
how to fix this.