在nestjs中设置允许跨域请求,并在Angular中配置http请求的选项。
app.enableCors();
import { HttpClient, HttpHeaders } from '@angular/common/http';
const headers = new HttpHeaders({'Content-Type': 'application/json'});
this.http.get('http://example.com', { headers: headers })
.subscribe(response => {
console.log(response);
});
其中,Content-Type可以根据实际需求进行修改。