var myApp = angular.module('myApp', []); myApp.directive('uiDate', function() { return { require: '?ngModel', link: function($scope, element, attrs, controller) { element.mask("99/99/9999",{completed: function() { controller.$setViewValue(Date.parse(this.val(),"dd/MM/yyyy")); $scope.$apply(); }}); } }; }); function Patient() { this.nom; this.prenom; this.dateNaissance; } function PatientController($scope) { $scope.patient = new Patient(); $scope.label = "Resultat : "; }
<div ng-app="myApp"> <div ng-controller="PatientController"> <label>Prénom: </label> <input ng-model="patient.prenom" type="text" placeholder="saisissez le prenom"> <br> <label>Nom: </label> <input ng-model="patient.nom" type="text" placeholder="puis le nom"> <br> <label>Date de naissance: </label> <input id="date" ng-model="patient.dateNaissance" ui-date> <hr> <h1> {{label}} {{patient.prenom}} {{patient.nom}} {{patient.dateNaissance | date: 'dd/MM/yyyy'}}</h1> </div> </div>