javascript - 在一种情况下,输入文本不会更新与相同形式的另一种情况相同的 Angular 模型

标签 javascript angularjs forms angular-ngmodel

我有一个简单的表单(从实际表单简化以演示问题):

<pre>Name: {{currentChild.name}}</pre>
<pre>Annual College Expense: {{currentChild.annualCollegeExpense}}</pre>
<form name="childForm" novalidate>
    <div class="form-inline">
        <div class="form-group">
            <label>Name:</label>
            <input type="text" name="name" class="form-control" ng-minlength="1" ng-model="currentChild.name" ng-required="true">
            <div class="help-block"
                 ng-messages="childForm.name.$error"
                 ng-show="childForm.$submitted || childForm.name.$dirty || (childForm.name.$invalid && childForm.name.$touched)">
                <p ng-message="required" ng-hide="childForm.name.$valid">Your name is required.</p>
                <p ng-message="minlength" ng-hide="childForm.name.$valid">Your name is too short.</p>
            </div>
        </div>
        <div class="form-group">
            <label>Annual Expenses:</label>
            <input type="text" name="annualCollegeExpense" class="form-control" ngModel="currentChild.annualCollegeExpense" />
        </div>
    </div>
</form>

当我启动表单时,我在表单顶部的 pres 中看到了预期的数据。当我在名称字段中输入内容时,预置中的名称会发生​​变化。当我在年度费用字段中输入时,年度费用预付款不会改变。

因为它们是相同的并且似乎遵守所有常见的 ng-model 规则,即使用 .要引用模型中的数据,我被难住了。

有人有建议吗?

最佳答案

您使用了 ngModel 而不是 ng-model 所以您应该使用

 ng-model="currentChild.annualCollegeExpense"

而不是

ngModel="currentChild.annualCollegeExpense"

使用

<input type="text" name="annualCollegeExpense" class="form-control" ng-model="currentChild.annualCollegeExpense" />

关于javascript - 在一种情况下,输入文本不会更新与相同形式的另一种情况相同的 Angular 模型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36728559/

相关文章:

javascript - 如果用户单击图标图像,如何显示 bsDatePicker 弹出窗口

javascript - 使用 HTML,如何将文件作为 excel 文件打开?

angularjs - Angular Controller 未注册错误

javascript - 静音数据uri?

javascript - Infragistics 网格导出到不同的位置

javascript - 如何在 AngularJS 中的两个独立模块之间共享数据

javascript - AngularJS + ASP.NET MVC - Controller 未定义

forms - 更改jQuery UI自动完成的查询参数

html - 使用 Bootstrap 使搜索输入宽度为 100%

ruby-on-rails - Rails - 相同表单的不同 form_for 语句