Javascript Can';t在动态路由中获取端口3000
目前,我正在努力从本地主机4200上提供的Angular应用程序中获取localhost:3000Javascript Can';t在动态路由中获取端口3000,javascript,angular,Javascript,Angular,目前,我正在努力从本地主机4200上提供的Angular应用程序中获取localhost:3000 角度版本:9.1.7 environment.ts(保存API url的位置): blogpost.component.ts(我遇到问题的组件): 有关此问题的其他一些信息: import { Component, OnInit } from "@angular/core"; import { environment } from "../../environme
- 角度版本:9.1.7
import { Component, OnInit } from "@angular/core";
import { environment } from "../../environments/environment";
@Component({
selector: "app-blogpost",
templateUrl: "./blogpost.component.html",
styleUrls: [ "./blogpost.component.scss" ]
})
export class BlogpostComponent implements OnInit {
id: string;
postdata;
async ngOnInit() {
console.log(`${environment.apiURL}/api/posts/get/id/${this.id}`);
// This console.logs http://localhost:3000/api/posts/get/id/undefined
let req = await fetch(`${environment.apiURL}/api/posts/get/id/${this.id}`);
// This sends a request to http://localhost:4200/api/posts/get/id/someid
this.postdata = await req.json();
}
}
- 我已经试过使用代理了,但不起作用
- fetch命令向其他组件上的端口3000发送请求
- 这个组件与其他组件的唯一区别在于它有一个动态路由
import { Component, OnInit } from "@angular/core";
import { environment } from "../../environments/environment";
@Component({
selector: "app-blogpost",
templateUrl: "./blogpost.component.html",
styleUrls: [ "./blogpost.component.scss" ]
})
export class BlogpostComponent implements OnInit {
id: string;
postdata;
async ngOnInit() {
console.log(`${environment.apiURL}/api/posts/get/id/${this.id}`);
// This console.logs http://localhost:3000/api/posts/get/id/undefined
let req = await fetch(`${environment.apiURL}/api/posts/get/id/${this.id}`);
// This sends a request to http://localhost:4200/api/posts/get/id/someid
this.postdata = await req.json();
}
}
import { BlogpostComponent } from "./blogpost/blogpost.component";
...
{ path: "post/:id", component: BlogpostComponent }