Sami
Sami

Reputation: 2331

How to change value notation of date input field in AngularJS

I would like to change format of date input field from dd/mm/yyy to dd.mm.yyyy Is it possible and how and is there any chance to get that datepicker working in another browsers as well?

<body ng-app="myApp">
    <div ng-controller="MyCtrl">
      <input type="date" ng-model="date" value="{{date}}">
        <p>{{date}}</p>
      <input type="time" ng-model="time" value="{{time}}">    
    </div>

How date looks now in Chrome Browser

Upvotes: 1

Views: 375

Answers (1)

Shushanth Pallegar
Shushanth Pallegar

Reputation: 2862

you can use custom filter for it as below

        <div ng-app="myApp">
           <div ng-controller="myCtrl">
             <p>{{date | divideByPoint}}</p> // displays as dd.mm.yyyy(21.12.2014)
          </div>
       </div>

below filter : divideByPoint

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

 //controller
      app.controller('myCtrl',myCtrl);

         myCtrl.$inject = ["$scope"];

         function myCtrl($scope){
            $scope.date = "21/12/2014"
       }

  //filter

    app.filter('divideByPoint',function(){

     var pattern = /\//g;  
        return function(input) {
              return input.replace(pattern,'.');
           }

     })

https://jsfiddle.net/shushanthp/9yes55L5/

Upvotes: 2

Related Questions