0

I'm using Angulars input datetime-local to generate a date-time-picker for a search function.

I want the user to select a start and end time and when the user clicks a button I want a function in my controller to be called with the selected times as passed parameters, but somehow all that is passed is undefined:

JsFiddle

HTML:

<div id="searchposition_popup" ng-app="dateExample">
<div id="searchposition-popup" ng-controller="DateController">
    <a class="searchposition_popup_close close" style="color:#FFFFFF; padding-right:10px;">x</a>
    <div style="padding-top:6px;">SEARCH POSITIONS</div>
    <br>
    <p>
        <label style="width:50px;">From:</label>
        <input style="width:180px;" type="datetime-local" id="startDate" name="input" ng-model="searchDateStart" placeholder="yyyy-MM-ddTHH:mm:ss" required />
    </p>
    <p>
        <label style="width:50px;">To:</label>
        <input style="width:180px;" type="datetime-local" id="endDate" name="input" ng-model="searchDateEnd" placeholder="yyyy-MM-ddTHH:mm:ss" required />
    </p>
    <br>
    <button type="Submit" ng-click="searchPositions(searchDateStart, searchDateEnd)" class="btn btn-default btn-xs">Search</span>
</div>

Javascript

angular.module('dateExample', [])
.controller('DateController', ['$scope', function ($scope) {
    $scope.searchPositions = function (begin, end) {
        console.log(begin, end);
    }
}]);

1 Answer 1

1

Angular dosen't support datetime-local in lower versions 1.3.0-beta.1
Make sure you use newer angular version or 1.3.0-beta.1 And bind your model with date objects:

var app = angular.module('dateExample', []);

app.controller('DateController', function($scope) {
  $scope.searchDateEnd = new Date();
  $scope.searchDateStart = new Date();
  $scope.searchPositions = function(begin, end) {
    console.log(begin, end);
  }
});

Plunker

Sign up to request clarification or add additional context in comments.

1 Comment

That is the reason why I put the Angular source as external, hence using version 1.4.3. And this did the trick.

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.