ng-model无法正常工作

时间:2016-03-09 19:10:57

标签: angularjs mongoose mean-stack

我正在研究MEAN Stack Web应用程序。我试图在我的一个模型中使用2D数组。这是特定字段的架构:

alerts:  [{ name: String, time: Number}]

现在我正在尝试在我的UI应用程序中访问它。这是我访问数据的方法。

控制器中的

代码:

 $scope.getalerts = function(){
          console.log("Getting Alerts Tasks...!");

            for (var i = 0; i < $scope.task.alerts.length; i++) {
                if ($scope.task.alerts[i].name == "NewUserAssigned") {
                            $scope.task.NewUserAssigned = true;
                            $scope.task.NewUserAssignedtime = $scope.task.alerts[i].time;
                        }
                    else if ($scope.task.alerts[i].name == "EditedDeleted") {
                            $scope.task.EditedDeleted = true;
                            $scope.task.EditedDeletedtime = $scope.task.alerts[i].time;
                        }

                }

视图中的代码:

                        <uib-tab index="4" heading="Alerts" class="nav nav-tabs">

                        <div id="task_alerts" class="tab-pane">

                            <div class="alert_block">
                              <div class="task_checkbox">
                                <input type="checkbox" class="checkbox-custom" id="assign_task_new_user" ng-model="task.NewUserAssigned" ng-checked="task.NewUserAssigned == true" alerts-block>
                                <label for="assign_task_new_user"  class="checkbox-custom-label">When a New User Assigned</label>
                              </div>
                              <div class="alert_reminder col-lg-5" ng-if="task.NewUserAssigned == true">
                                <select class="alert_reminder_dd" ng-model="task.NewUserAssignedtime" >
                                  <option value="1">1 Day Prior</option>
                                  <option value="2">2 Day Prior</option>
                                  <option value="3">3 Day Prior</option>
                                  <option value="4">4 Day Prior</option>
                                </select>
                                <div class="dd_caret"></div>
                              </div>
                            </div>

                            <div class="alert_block">
                              <div class="task_checkbox">
                                <input type="checkbox" class="checkbox-custom" id="edit_delete_task" ng-model="task.EditedDeleted" ng-checked="task.EditedDeleted == true" alerts-block>
                                <label for="edit_delete_task" class="checkbox-custom-label">Task is Edited / Deleted</label>
                              </div>
                              <div class="alert_reminder col-lg-5" ng-if="task.EditedDeleted == true">
                                <select class="alert_reminder_dd" ng-model="task.EditedDeletedtime">
                                  <option value="1">1 Day Prior</option>
                                  <option value="2">2 Day Prior</option>
                                  <option value="3">3 Day Prior</option>
                                  <option value="4">4 Day Prior</option>
                                </select>
                                <div class="dd_caret"></div>
                              </div>
                            </div>


                        </div>   

                    </uib-tab>

如果我调试它,它会正确保存数据。但是当它从数据库访问数据时,它做的是它正确地检查选项但不更新时间模型中的值。第二件事是它没有在控制台上显示数组值(在从数据库获取值之后)。

1 个答案:

答案 0 :(得分:0)