简体   繁体   中英

AngularJS $http.get not firing

I have a page that has a datepicker on it. When a date is picked I have a function being called which assigns the new date to a variable and then calls a $http.get.

The variable gets assigned fine as I have this returning to the page but the $http.get fails and I cant see why. The call syntax is fine as I use it in another function and when I look at the Network viewer in IE I can see that its not even being fired.

Any help would be great. Thanks :-)

The 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>

and the 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);
    }
});

请在控制器声明中注入$ http服务,例如

controller("timesheetViewerCtrl", function ($scope, $http)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM