【问题标题】:pick-a-date datepicker set value to empty at time of edit in angularjs在angularjs中编辑时选择日期日期选择器将值设置为空
【发布时间】:2016-03-04 12:24:33
【问题描述】:

在编辑表单时, 在下面的代码中..我从字段中获取 json 到行变量.. 它显示了“row.create_tour.startDate”和“row.create_tour.endDate”的值..当我在表格开头打印它们时.. 但是,当我将这些模型分配给pick-a-date时,它会变空..我该怎么办? 选择日期是否有任何默认设置?在具有选择日期的输入框中显示值的任何其他选项?

下面是sn-p的代码:

            <div ng-repeat="row in fields"> 
                        <div layout="row"> 
                            <div class="dateField">
                                <md-input-container> 
                                    <label>Start date <span class="requiredStart">*</span> </label>  

                                    <input type="text" name="startDate[$index]" class="inputbox required startDate" pick-a-date="startDate[$index]" pick-a-date-options="options" min-date="create_tour.startDate" ng-model="row.create_tour.startDate" ng-change="updateChildEndDate(row);" required/>
                                    <span style="color:red;font-size: 14px;" ng-show="step3Form.startDate[$index].$dirty &&  step3Form.startDate[$index].$invalid">
                                        <span ng-show="step3Form.startDate[$index].$error.required" >This field is required</span>
                                    </span>  

                                </md-input-container>  
                            </div>
                            <div class="dateField">   
                                <md-input-container>
                                    <label>End date <span class="requiredStart">*</span></label>
                                    <input type="text" name="endDate[$index]"  class="inputbox required endDate"   ng-model="row.create_tour.endDate" pick-a-date="endDate[$index]" min-date="row.create_tour.startDate" required/>
                                    <span style="color:red" ng-show="step3Form.endDate[$index].$dirty && step3Form.endDate[$index].$invalid"> 
                                        <span ng-show="step3Form.endDate[$index].$error.required" >This field is required</span>
                                    </span> 
                                </md-input-container>
                            </div>
                        </div>
            </div>

【问题讨论】:

    标签: jquery angularjs datepicker pickadate


    【解决方案1】:

    我认为您的models 有点错误。他们不应该是

    ng-model="row.create_tour.startDate[$index]"ng-model="row.create_tour.endDate[$index]" 分别。

    之所以如此,是因为ng-repeat 创建了自己的scope,并且每一行都应该有其唯一的ng-model

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多