Carsten Farving
Carsten Farving

Reputation: 541

Angular passing values from Input Datetime-local as parameters

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);
    }
}]);

Upvotes: 0

Views: 915

Answers (1)

Vicky Gonsalves
Vicky Gonsalves

Reputation: 11717

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

Upvotes: 1

Related Questions