Метод Post в Reactive Forms Angular 8 - PullRequest
0 голосов
/ 20 октября 2019

Я создал мою реактивную форму под названием Compaign, и я почти закончил с серверной части! Я работаю на фронтенде !! Я хочу зарегистрировать форму через мой пользовательский интерфейс. Однако получается ошибка подключения 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' ,
};

1 Ответ

0 голосов
/ 21 октября 2019

Попробуйте удалить часть localhost из:

this.http.post( environment.apiBaseUrl+'/register',compaignform);

На текущий сервер будут сделаны вызовы httpClient:

this.http.post('/api/register',compaignform);
...