2

I try to set the default value of an input field at today. I can do that with an text field but when I try with an date field it fails.

HTML code :

<div ng-controller="MyCtrl">
    <form name="new">
        <input type="date" ng-model="date_rdv" />
        <input type="text" ng-model="form_text" />
    </form>
</div>

JS code :

var myApp = angular.module('myApp',[]);
function MyCtrl($scope, $filter) {
    $scope.form_text = $filter('date')(Date.now(), 'yyyy-MM-dd');
    $scope.date_Rdv = $filter('date')(Date.now(), 'yyyy-MM-dd');
}

Why it works with text field and not with date field ?

JSFiddle.

1 Answer 1

5

You are not referencing the correct property of $scope.

Either use:

$scope.date_rdv = $filter('date')(Date.now(), 'yyyy-MM-dd');

Or

<input type="date" ng-model="date_rdv" />.

I've updated your fiddle here:

http://jsfiddle.net/68j7y439/1/

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

1 Comment

No problem, always good to have an extra pair of eyes some times!

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.