javascript - 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
未更新值。第二次单击 时使用表单值更新newForm
createForms()
newForm
有谁知道为什么会这样??
解决方案
推荐阅读
- c++ - 编译器错误:“非静态成员引用必须相对于特定对象”
- c++ - 让 OpenCV 在 MacOS 上的 CLion 中运行很难
- sql - search line break in several tables and get the rowid
- audio - 如何流式传输桌面声音而不是与 obs 的传入语音聊天
- python - Venv 未包装导致找不到模块的第三方库
- python - 填充通过检查不同数据框的列之间添加的新列
- php - Laravel 8 不会从数据库中删除数据
- c# - C# ASP.NET Core 替代扩展方法来注册服务
- python - 使用 RTX GPU 关闭 tensorflow 会话
- r - 构建一个用于在有效边界上挑选投资组合的 for 循环