0

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);
    }
});
1
  • 2
    If you run this with your browsers dev tools and console open you would see the error. Vineet is right with it being in reference to the missing service reference Commented Aug 5, 2015 at 20:56

1 Answer 1

4

Please inject $http service in your controller declaration like

controller("timesheetViewerCtrl", function ($scope, $http)
Sign up to request clarification or add additional context in comments.

1 Comment

@DeeSheehan please accept the answer for future uses.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.