I am trying to list cities and just print them in console but getting errors.
I added cors in program.cs:
builder.Services.AddCors();
app.UseCors(m => m.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod());
Then in my service.ts:
getAllCities(): Observable<string[]>{
return this.http.get<string[]>('http://localhost:5133/api/city');
}
and in the add-property.ts
this.housingService.getAllCities().subscribe(data => {
console.log(data);
})
I am getting error:
HttpErrorResponse
error
:
ProgressEvent {isTrusted: true, lengthComputable: false, loaded: 0, total: 0, type: 'error', …}
headers
:
HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, headers: Map(0)}
message
:
"Http failure response for http://localhost:5133/api/city: 0 Unknown Error"
name
:
"HttpErrorResponse"
ok
:
false
status
:
0
statusText
:
"Unknown Error"
url
:
"http://localhost:5133/api/city"