【发布时间】:2016-06-16 11:57:02
【问题描述】:
这是html页面
<form name="createPromoterFormName">
<div class="col s12" ng-repeat="customer in model.customers" ng-if="model.selectedCustomerSubtab == $index">
<div class="row inputcontainer">
<div class="input-field col s4">
<input placeholder="First Name" type="text" ng-model="customer.customer_name" class="validate" ng-maxlength="50" ng-required="true" />
<label class="active labelName">Customer Name </label>
</div>
<div class="input-field col s4">
<input type="text" class="validate" ng-maxlength="50" ng-required="true" ng-model="customer.avg_monthly_sales" />
<label class="active labelName">Average Monthly Sales </label>
</div>
<div class="input-field col s4">
<select ng-model="customer.avg_payment_cycle_days" ng-options="i.value as i.value for i in model.avgPaymentCycleDays" ng-change="changeSelectedItem()">
<option value="">Select Average Payment Cycle Days</option>
</select>
<label class="labelName">Avg Payment Cycle Days [[customer.avg_payment_cycle_days]]</label>
</div>
</div>
<div class="row inputcontainer">
<div class="input-field col s4">
<input type="text" class="validate" ng-maxlength="50" ng-model="customer.avg_paymmonths_in_business_with_customerent_cycle_days" />
<label class="active labelName">Months in business with customer</label>
</div>
</div>
</div>
</form>
Controller.js
$scope.model = {
customers: [{
customer_name: "",
avg_monthly_sales: "",
avg_payment_cycle_days: "",
months_in_business_with_customer: ""
}, {
customer_name: "",
avg_monthly_sales: "",
avg_payment_cycle_days: "",
months_in_business_with_customer: ""
}, {
customer_name: "",
avg_monthly_sales: "",
avg_payment_cycle_days: "",
months_in_business_with_customer: ""
}],
avgPaymentCycleDays : [{
value: '15',
id: '1'
}, {
value: '30',
id: '2'
}, {
value: '45',
id: '3'
}, {
value: '60',
id: '4'
}, {
value: '75',
id: '5'
}, {
value: '90',
id: '6'
}],
selectedPromoterSubtab: 0,
selectedCustomerSubtab: 0,
}
$scope.changeSelectedItem = function() {
console.log($scope.model.customers);
}
我正在使用材料 css。当我选择选项时,ng-change 没有触发,也没有将数据绑定到 ng-model。
谁能帮我看看我哪里出错了?
【问题讨论】:
-
我根据您的代码创建了一个 plunker,它似乎工作正常。 plnkr.co/edit/Zq8PDunpAh82Sij8WnAO?p=preview 。一定是其他东西破坏了它。
-
@Deep:我同意你的看法。在我的情况下也可以正常工作。检查您的 javascript 是否正在加载或文件路径等其他基本内容。或共享您的完整控制器。
-
我也保留了输入框...ng-model数据绑定正在工作,但不适用于选择
-
您的具体问题是什么?我可以看到 ng-change 工作正常。您是否担心 select 中的 ng-model 没有正确选择选项?
-
平均付款周期天数 [[customer.avg_payment_cycle_days]] 此数据不具有约束力...屏幕上没有任何内容
标签: angularjs html-select angular-ngmodel angularjs-select