NgModel第一次onclick角5不会更新

时间:2019-01-16 13:49:07

标签: javascript angular data-binding angular-ngmodel

我的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不会在第一次单击(触发newForm)上更新createForms()上的值。在第二次单击时newForm已更新为表单值

有人知道为什么会这样吗?

0 个答案:

没有答案