javascript - Placeholder Date with ANGULAR date.now() doesn't work in Chrome -
in web application have input type="date"
, i'd user had current date default. used angular because in pure js didn't work on phone (although in browser worked). html part:
<body ng-app="app"> <form ng-controller="datecontroller datectrl"> <input type="date" id="date" value="{{value}}" ng-model="value" placeholder="dd-mm-yyyy"> </form> </body>
and angularjs code:
var app = angular.module('app', []); app.controller('datecontroller', ['$scope', '$filter', function($scope, $filter) { $scope.value = $filter('date')(date.now(), "dd-mm-yyyy"); }]);
both firefox , chrome give me error in console. in firefox works, , in chrome doesn't work. chrome error:
the specified value '{{value}}' not conform required format, 'yyyy-mm-dd'. angular.min-1.4.5.js:107 error: [ngmodel:datefmt] http://errors.angularjs.org/1.4.5/ngmodel/datefmt?p0=08-02-2016 @ error (native) @ file:///mypath/js/angular.min-1.4.5.js:6:416 @ array. (file:///mypath/js/angular.min-1.4.5.js:165:14) @ object. (file:///mypath/js/angular.min-1.4.5.js:264:75) @ m.$get.m.$digest (file:///mypath/js/angular.min-1.4.5.js:129:480) @ m.$get.m.$apply (file:///mypath/js/angular.min-1.4.5.js:133:113) @ file:///mypath/js/angular.min-1.4.5.js:19:479 @ object.e [as invoke] (file:///mypath/js/angular.min-1.4.5.js:39:96) @ d (file:///mypath/js/angular.min-1.4.5.js:19:400) @ yc (file:///mypath/js/angular.min-1.4.5.js:20:179)(anonymous function) @ angular.min-1.4.5.js:107$get @ angular.min-1.4.5.js:80$get.m.$digest @ angular.min-1.4.5.js:130$get.m.$apply @ angular.min-1.4.5.js:133(anonymous function) @ angular.min-1.4.5.js:19e @ angular.min-1.4.5.js:39d @ angular.min-1.4.5.js:19yc @ angular.min-1.4.5.js:20zd @ angular.min-1.4.5.js:19(anonymous function) @ angular.min-1.4.5.js:292m.callbacks.j @ jquery.min.js:2m.callbacks.k.firewith @ jquery.min.js:2m.extend.ready @ jquery.min.js:2j @ jquery.min.js:2 jquery.min.js:5
the specified value '08-02-2016' not conform required format, 'yyyy-mm-dd'.
- first of all, engines not support date.now function. ( described in https://developer.mozilla.org/en-us/docs/web/javascript/reference/global_objects/date/now) can
$scope.value= new date();
or$scope.value= new date(date.now());
- second of all, input type date think unformattable. takes system default , applies gui. have go
<input type="date" id="date" ng-model="value" placeholder="dd-mm-yyyy">
Comments
Post a Comment