Post 反应形式中的方法 Angular 8
Post method in Reactive Forms 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() */
......
);
}
}
compaign.service.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;
}
}
environment.ts
export const environment = {
production: false ,
apiBaseUrl: 'http://localhost:3000/api' ,
};
尝试从以下位置删除本地主机部分:
this.http.post( environment.apiBaseUrl+'/register',compaignform);
将对当前服务器进行 httpClient
次调用:
this.http.post('/api/register',compaignform);
我创建了名为 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() */
......
);
}
}
compaign.service.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;
}
}
environment.ts
export const environment = {
production: false ,
apiBaseUrl: 'http://localhost:3000/api' ,
};
尝试从以下位置删除本地主机部分:
this.http.post( environment.apiBaseUrl+'/register',compaignform);
将对当前服务器进行 httpClient
次调用:
this.http.post('/api/register',compaignform);