0

这是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>

控制器.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。

任何人都可以帮助我我在哪里犯错误?

这是 plnkr 链接

4

2 回答 2

1

问题是您包含脚本文件的顺序。

检查柱塞。

https://plnkr.co/edit/eFL48s3UyhwdTFzwTR05

ng-model 正确绑定并且 ng-change 也被正确触发。

<script data-require="jquery" data-semver="3.0.0" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/js/materialize.min.js"></script>
<script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.9/angular.js" data-semver="1.4.9"></script>
于 2016-06-16T13:59:09.877 回答
0

首先 ng-selected 不是必需的。如果下拉列表具有该值,ng-model 将自动检测必须从下拉列表中选择的任何内容。

因此,将您的选择更改为

<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>

根据您的 plnkr 还包括 jquery,您还没有包括

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script> 
  <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.6/js/materialize.min.js"></script>
  <script data-require="angular.js@1.4.x" src="https://code.angularjs.org/1.4.9/angular.js" data-semver="1.4.9"></script>
  <script src="app.js"></script>

这是工作的plnkr

https://plnkr.co/edit/p7t7KcNmChZlT5Jg0pr2?p=preview

于 2016-06-16T12:02:43.463 回答