2016-08-11 92 views
1

我正在将Angular 2 Beta 9中的应用程序迁移到Angular 2 RC5,并且我遇到了大量的错误,我开始消除并且达到了我的控制台不显示任何内容的地步。Angular 2在POST请求上重新加载页面

然而,当我提交表单到轨服务器,页面只是重新加载和控制台迅速显示了一个错误,但我不能把它看作是低于其过快

反正代码的工作只是罚款公测版本,所以这是怎么回事错在这里的任何见解将是真棒(张贴只是相关部分)

onSubmit() { 

    this.myForm.value.systemParameters = this.system_arr; 
    this.myForm.value.liftOperator = this.lift_arr; 
    this.myForm.value.restrictOperator = this.restrict_arr; 
    this.myForm.value.param = this.param_arr; 
    this.myForm.value.xInitial = this.xinitial_arr; 

    let myForm = JSON.stringify(this.myForm); 

    let headers = new Headers(); 
    headers.append('Content-Type', 'application/json'); 
    this.http.post('http://localhost:3000/webhook', myForm, { headers: headers }).subscribe(
     res => this.response = res.json(), 
     error => console.log(error) 
    ); 

    console.log('your submitted value:', this.myForm.value); 
    } 
+0

包裹错误处理括号,所以你可以在那里坚持一个断点,看看是什么错误 – drewmoore

+0

啊,你可以举个例子吗?不知道我得到它 –

+0

取代'误差= > console.log(error)'with'error => {debugger; }',并且执行将在调试器行上暂停。或者单独离开'console.log',并在devtools中添加一个断点。我假设你知道如何使用chrome devtools? – drewmoore

回答

1

我不知道如果我正确地理解你的问题,但如果问题是页面重载每一个岗位后请求我会建议将提交按钮的类型更改为“按钮”。这将防止在向服务器发送POST请求时重新加载页面。

喜欢这个家伙表明https://stackoverflow.com/a/33304509/4332884

相关问题