我有一个用AngularJS编写的报告生成器。当我不使用jQuery日期选择器时,它工作正常。当我使用jQuery日期选择器时,从服务器返回的数据是正确的,但前端不会改变。如果我去纯粹的棱角分明,那么我的演示效果非常好,如下所示答案很简单,使用带角度代码的角度日期选择器来避免问题?
在我的angularJS控制器中,我有:
as.controller('ReportController', function ($scope, $rootScope, $http, $location) {
var currentDate = new Date();
// works
$scope.loadToday = function () {
// not sure why this is necessary here
currentDate = new Date();
$scope.load();
};
// does not work
$scope.setDateAndLoad = function (newDate) {
$scope.currentDate = newDate;
$scope.load();
};
$scope.decrementWeekAndLoad = function () {
currentDate.setDate(currentDate.getDate() - 7);
$scope.load();
};
// works depending on method
$scope.load = function () {
$scope.showTable = false;
$scope.currentDate.setHours(0, 0, 0, 0);
var formattedDate = $scope.currentDate.toISOString();
$http.get('/app/client/report/${user.id}?startDate=' + formattedDate)
.success(function (data, status, headers, config) {
$scope.report = angular.copy(data);
// $scope.report is not getting rebound
$scope.showTable = true;
});
};
$scope.loadToday();
并绑定到以下HTML代码:
<section id="show-client" class="first" ng-app="myApp">
<div id="reportController" class="form-group" ng-controller="ReportController">
<div ng-hide="showTable">
Loading . . .
</div>
<div ng-show="showTable">
Behavior {{report}}
</div>
<input id="datepicker" name="datepicker" class="datepicker">
在jQuery日期选择器中,我有:
$(document).ready(function () {
$('#datepicker').datepicker({
dateFormat: 'dd-M-yyyy'
}).on('changeDate', function (ev) {
var newDate = new Date(ev.date);
angular.element('#reportController').scope().setDateAndLoad(newDate);
$(this).datepicker('hide');
});
});
答案 0 :(得分:0)
旧订单: - 角度 - jQuery - 角度(是的,包括两次)
新订单: - jQuery - 角度
按预期工作。