angular - 反应形式Angular 8中的发布方法
问题描述
我创建了名为“我的响应式表单” Compaign
,而我几乎从后端部分完成了!我在前端工作!我想通过我的 UI 注册表单但是结果是连接 localhost:3000/api/register 的错误!我使用邮递员通过我的后端进行了尝试,它可以工作!但是在我的前端,当我保存我的输入时;控制台显示此错误http://localhost:3000/api/register net::ERR_CONNECTION_REFUSED
我现在很困惑!
compaign.component.ts
export class CompaignComponent implements OnInit {
compaignexample : FormGroup ;
showSucessMessage : boolean ;
serverErrorMessage: String ;
ngOnInit () {
this.compaignexample = new FormGroup ({
requestidname: new FormControl('', Validators.required),
integritykeyname : new FormControl(),
})
}
constructor ( private _compaignService : CompaignService) {}
saveCompaign() {
let compaignform: CompaignForms = new CompaignForms(
this.compaignexample.get('requestidname').value,
this.compaignexample.get('integritykeyname').value,
);
console.log(compaignform);
this._compaignService.postCompaign(compaignform).subscribe( */ I have some doubts on this
Line I dont know which parameter should I put for postCompaign() */
......
);
}
}
竞争服务.ts
@Injectable ({
providedIn : 'root'
})
export class CompaignService {
selectedCompaign : CompaignForms = {
requestid: null ,
integritykey: ''
};
constructor (private http :HttpClient) { }
postCompaign(compaignform : CompaignForms) {
return this.http.post( environment.apiBaseUrl+'/register',compaignform);
}
}
compaignexample.model.ts
export class CompaignForms {
requestid : Number;
integritykey:String;
constructor(requestid: Number,integritykey) {
this.requestid =requestid ;
this.integritykey=integritykey;
}
}
环境.ts
export const environment = {
production: false ,
apiBaseUrl: 'http://localhost:3000/api' ,
};
解决方案
尝试从以下位置删除 localhost 部分:
this.http.post( environment.apiBaseUrl+'/register',compaignform);
httpClient
将对当前服务器进行调用:
this.http.post('/api/register',compaignform);
推荐阅读
- apache-kafka - Apache-Kafka:使用 windows cmd 创建主题时出现问题
- python - 尝试使用 Solve_ivp 求解牛顿多面体,并且正确性因 n 的不同值而异?
- javascript - 如何在 vuejs 中生成每个版本的新版本?
- python - 二叉搜索树的最低共同祖先
- hadoop - 在 HDFS 中看不到数据,使用 sqoop 从 mariadb 导入表到 Hadoop
- visual-studio - 如何将英特尔 Parallel Studio XE 中的 Fortran 编译器与 Visual Studio 结合使用
- bazel - 谁能详细说明如何在 C++ 规则中实现像 local_defines 这样的属性?
- java - 无法在 intellij 中创建类
- python - 迭代数据库数组烧瓶
- django - Django 返回 None 而不是 HTTP 响应