I’m using ASP.NET Core Web API pass JSON data and consume that in Ionic 4 service.
I add addCores in startup.cs at my ASP.NET core Web API
services.AddCors(options =>
{
options.AddPolicy(“AllowOrigin”,
builder =>
{
builder.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod();
});
});
app.UseCors(“AllowOrigin”);
It is work well in browser/ Chrome.
However, if I try “ionic serve --devapp” chrome is fine. but devapp has not showing data and console had this error.
How can I fix this?
my http call service code is below:
import { Injectable } from ‘@angular/core’;
import { HttpClient, HttpHeaders } from ‘@angular/common/http’;
@Injectable({
providedIn: ‘root’
})
export class RestService {
apiUrl = ‘https://localhost:5001/api/orientation-startup’;
constructor(public http: HttpClient) { }
getContent(){
return new Promise(resolve =>{
this.http.get(this.apiUrl).subscribe(data =>{
resolve(data);},
err => {
console.log(err);
});
});
}