首页 > 解决方案 > NgModel在第一次onclick angular 5时没有更新

问题描述

我的 angular5 应用程序有一个奇怪的问题,我正在尝试进行简单的表单提交

ts

export class NewFormComponent implements OnInit {
  formSlug:'';

  newForm = { 
    title:"",
    description:" ", 
    allowMultiSubmit:""
  }

  //create new form
  createForms() {
      this.formsSandbox.createNewFormPartial(newForm).subscribe((result: any) => {
          console.log('created');
      });
  }


}

HTML

<div class="new_form_wrap_body">
      <div class="new_form_content">
        <div class="new_form_content_row">
          <input type="text" placeholder="Title" class="new_form_input" [(ngModel)]="newForm.title">
        </div>
        <div class="new_form_content_row">
          <textarea class="new_form_textarea" [(ngModel)]="newForm.description" maxlength="250" placeholder="Description"></textarea>
        </div>
        <div class="new_form_content_row">
            <div class="checkbox">
                <label>
                  <div class="check_outer">
                    <input name="" type="checkbox" [(ngModel)]="newForm.allowMultiSubmit">
                    <div class="check" for="1_in"></div>
                  </div>
                </label>
                <span>Allow multiple submission</span>
              </div>

        </div>
        <!-- <div class="new_form_content_row">
          <input type="text" placeholder="Add Collaborators" class="new_form_short_input">
        </div> -->
      </div>
    </div>
    <div class="new_form_wrap_footer">
      <ul>
        <li>
 <button (click)="createForms()" class="new_form_footer_next">Create</button>

这在开发中运行良好。当我将此推送到在 apache 下提供服务的测试服务器(dist 文件夹已上传)时,第一次单击(触发器)时ngModel未更新值。第二次单击 时使用表单值更新newFormcreateForms()newForm

有谁知道为什么会这样??

标签: javascriptangulardata-bindingangular-ngmodel

解决方案


推荐阅读