Angular 2 根据 POST 请求重新加载页面

标签 angular

我正在将一个应用程序从 Angular 2 Beta 9 迁移到 Angular 2 RC5,我遇到了大量错误,我开始消除这些错误,但我的控制台却没有显示任何错误。

但是,当我向 Rails 服务器提交表单时,页面会重新加载,控制台会快速显示错误,但我看不到它太快了

无论如何,下面的代码在测试版上运行得很好,所以对这里出了什么问题的任何见解都会很棒(只发布相关部分)

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);
  }

最佳答案

我不确定我是否正确理解您的问题,但如果问题是每次 POST 请求后页面重新加载,我建议将提交按钮的类型更改为“按钮”。这将防止页面在向服务器发送 POST 请求时重新加载。

喜欢这个人建议 https://stackoverflow.com/a/33304509/4332884

关于Angular 2 根据 POST 请求重新加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38905669/

相关文章:

javascript - 通过 Promise.then 混契约(Contract)步和异步不起作用

Angular MatPaginator 没有被初始化

Angular 2 Web Pack 404 Html 模板网址

angular - 如何更改延迟加载 Angular 2 查找 block 的位置?

css - 如何在 Angular 中使用 FontAwesome 作为字体系列

angular - 错误未捕获( promise ): TypeError: Object(. ..)不是函数

angular - 为什么在 Stripe 付款请求按钮上出现错误?

angular - agm-marker 的 markerClick() 返回 null

嵌套 ControlValueAccessor 的 Angular 验证状态未在父级中正确传播,如何实现此验证?

javascript - Angular 模板引用 : Bind height of one div to height of another