我有这个 Angular 7 应用程序,它运行良好,直到我决定将我的逻辑从 app.component.ts 文件移到新的 login.component.ts 文件中。自从我这样做以来,当我尝试登录并且应用程序查询数据库时,它使用错误的网址 - 4200 而不是 3000。我设置了一个 proxy.conf.json 文件,如下所示:
{
"/api": {
"target": "http://localhost:3000",
"secure": false
}
}
这实际上在我切换 app.component.ts 文件之前就已经设置好了。除了重新连接从移动到另一个组件的所有内容之外,我没有进行任何其他更改。我找不到 Angular 指向 localhost:4200 而不是 3000 的位置。有人有什么想法吗?提前致谢。把我的头撞到墙上。我的操作系统是运行 VS Code 的 Windows 10。
这是我下一期的错误:
VM623:37 ERROR TypeError: Cannot read property '0' of undefined
at
LoginComponent.push../src/app/login/login.component.ts.LoginComponent.toPrint
这是与此错误相关的两个函数:
toPrint(match) {
return `Name: ${this.match[0].name} Checking: ${this.match[0].checking}
Savings: ${this.match[0].savings}`
}
printUserData(match){
this.buttonPressed = true;
return this.loginComponent.toPrint(match);
}
最佳答案
只需将您的代理配置包含在 angular.json 文件中,以便在您运行应用程序时它也会运行您的代理。
示例 -
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "movie-analysis:build",
"proxyConfig": "src/proxy.conf.json"
},
"configurations": {
"production": {
"browserTarget": "movie-analysis:build:production"
}
}
}
希望有帮助:)
关于node.js - Angular 使用错误的 URL 通过 NodeJS 查询 MongoDB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54940484/