角度代码:
$scope.activitiesmonth = [];
//get array data from server
$scope.getActivityMonth = function(){
var userID = sessionService.get('user');
var matcher = moment().format('YYYY-MM');
$http({
method: 'POST',
url: 'getactivitymonth.php',
data: {
matcher : $scope.matcher,
userID : userID
}
}).success(function (data,status) {
$scope.activitiesmonth = data;
});
}
//save new data to database and update array
$scope.saveActivity = function(){
var matcher = moment().format('YYYY-MM');
if($scope.activityname == null || $scope.activitytype == null){
alert("Please complete the form!");
} else {
var userID = sessionService.get('user');
var activityId = parseInt($scope.activitiesmonth[$scope.activitiesmonth.length-1].activityID) + 1;
$scope.obj = {
0 : activityId.toString(),
1: $scope.activityname,
2: $scope.activitytype,
3: $scope.momentClicked,
4: $scope.hour,
5: userID,
activityFullDate : $scope.momentClicked,
activityID : activityId.toString(),
activityName : $scope.activityname,
activityTime : $scope.hour,
activitytype : $scope.activitytype,
userID : userID
}
$http({
method: 'POST',
url: 'postactivity.php',
data: {
activityname : $scope.activityname,
activitytype : $scope.activitytype,
date : $scope.momentClicked,
time : $scope.hour,
userID : userID
}
}).success(function (response, data) {
$timeout(function() {
$scope.activitiesmonth.push($scope.obj);
},500);
});
$uibModalInstance.close();
}
}
HTML代码:
<div class="header">
<table class="table table-bordered">
<thead>
<tr>
<th id="acadWeekHeader">{{semester}}</th>
<th id="daysHeader" ng-repeat="day in daysInWeek">
{{ day }}
</th>
</tr>
</thead>
<tbody>
<tr class="days" ng-repeat="week in daysArray">
<td class="acadWeek" dragula='"second-bag"'>{{weeksArray[$index]}}</td>
<td id="{{day}}" ng-repeat="day in week track by $index" ng-class="{'greyOut':isNumber(day), 'highlight':isString(day), 'currentDay':isCurrentDay(day)}" ng-click="check(day)" dragula='"second-bag"'>
<div ng-show="isString(day) == true" id="day">{{day}}</div>
<div ng-show="isNumber(day) == true" id="day">{{day}}</div>
<ul class="list-group" ng-repeat="activity in activitiesmonth | filter:filterDate(day) track by $index" ng-switch="activity.activityType" dragula='"second-bag"'>
<li class="list-group-item list-group-item-warning" ng-switch-when="Quiz and Exam" id="{{ activity.activityID }}" ng-click="click()">
<span clas="trash" ng-click="deleteActivity(activity.activityID, $event)"><i class="fa fa-trash" aria-hidden="true"></i></span>
<span class="activitynames">{{activity.activityName}}</span><br>
<span class="datetimes">{{activity.activityTime}}</span>
</li>
<li class="list-group-item list-group-item-danger" ng-switch-when="Assignment Deadline" id="{{ activity.activityID }}" ng-click="click()">
<span clas="trash" ng-click="deleteActivity(activity.activityID, $event)"><i class="fa fa-trash" aria-hidden="true"></i></span>
<span class="activitynames">{{activity.activityName}}</span><br>
<span class="datetimes">{{activity.activityTime}}</span>
</li>
<li class="list-group-item list-group-item-success" ng-switch-when="CCA Activity" id="{{ activity.activityID }}" ng-click="click()">
<span clas="trash" ng-click="deleteActivity(activity.activityID, $event)"><i class="fa fa-trash" aria-hidden="true"></i></span>
<span class="activitynames">{{activity.activityName}}</span><br>
<span class="datetimes">{{activity.activityTime}}</span>
</li>
<li class="list-group-item list-group-item-info" ng-switch-when="Leisure Activities and Other" id="{{ activity.activityID }}" ng-click="click()">
<span clas="trash" ng-click="deleteActivity(activity.activityID, $event)"><i class="fa fa-trash" aria-hidden="true"></i></span>
<span class="activitynames">{{activity.activityName}}</span><br>
<span class="datetimes">{{activity.activityTime}}</span>
</li>
</ul>
</td>
</tr>
</tbody>
每次将新数据推送到$ scope.activitiesmonth数组时,我都会尝试更新视图。但它告诉我“$ digest已在进行中”错误。我该怎么做才能更新视图?非常感谢提前!