Reputation: 31
i have an error
Access to XMLHttpRequest at 'http://localhost:3000/framework/create' from origin 'http://localhost:4200' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
how i fix it?
i'm use angular v7 and express.js for backend
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
@Injectable({providedIn : 'root'})
export class CommonService {
uri = 'http://localhost:3000/framework';
constructor(private http: HttpClient) { }
addFramework(framework, bahasa) {
const obj = {
framework: framework,
bahasa: bahasa
};
console.log(obj);
this.http.post(`${this.uri}/create`, obj)
.subscribe(res => console.log('Done'));
}
}
Upvotes: 1
Views: 2621
Reputation: 209
if you are using chrome, just go to https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi and intall it. refresh the page and it should work.
Upvotes: -1