我有一个页面上有一个日期选择器。当选择一个日期时,我有一个被调用的函数,它将新日期分配给变量,然后调用$ http.get。
变量被分配得很好,因为我有这个返回页面,但$ http.get失败,我不明白为什么。调用语法很好,因为我在另一个函数中使用它,当我在IE中查看网络查看器时,我可以看到它甚至没有被触发。
任何帮助都会很棒。 谢谢: - )
HTML
<div>
<div id="date-picker" class="panel panel-heading" ng-controller="timesheetViewerCtrl">
<!--<div>
Choose A Week End Date:
<select ng-model="selectedWeek" ng-options="val for val in years"> </select>
</div>-->
<pre>Selected date is: <em>{{dt | date:'fullDate' }}</em></pre>
<div class="row">
<div class="col-md-6">
Choose a Week End Date:
<p class="input-group">
<input type="text" class="form-control" datepicker-popup="{{format}}" ng-model="dt"
is-open="opened" min-date="minDate" max-date="'2020-06-22'" datepicker-options="dateOptions"
date-disabled="isDateDisabled(date, mode)" ng-required="true" ng-change="changeSelect(dt)"
close-text="Close" />
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="open($event)"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
</div>
</div>
<pre>{{changeDate}}
<br>To Check Filter Select any of the following (joining date) from Datepicker.
</pre>
</div>
和JS
angular.module("timesheetApp").controller("timesheetViewerCtrl", function ($scope) {
$scope.dt = new Date();
$scope.open = function (e) {
e.preventDefault();
e.stopPropagation();
$scope.opened = true;
};
$scope.dateOptions = {
'starting-day': 1
};
$scope.format = 'dd-MM-yyyy';
$scope.isDateDisabled = function (date, mode) {
return (mode === 'day' && date.getDay() !== 0);
};
$scope.changeSelect = function (dt) {
$scope.changeDate = moment(dt).format("MM-DD-YYYY");
$http.get("/api/tblEntries/")
.then(onUserComplete, onError);
}
});
答案 0 :(得分:4)
请在您的控制器声明中注入$http服务,例如
controller("timesheetViewerCtrl", function ($scope, $http)