Angular input box uses filter to format the date, angularfilter
Angular date selector is used recently. However, you need to output the selected date to the input box. If the selected date is displayed as a timestamp by default, it does not meet the requirements, the format must be changed to a specific format, but the ng-model on the input cannot directly use the filter. Therefore, you need to format the content displayed here.
To find a solution online, write direve VE. The specific instance code is as follows:
JS
angular.module('dateRange',[]).directive('dateFormat', ['$filter',function($filter) { var dateFilter = $filter('date'); return { require: 'ngModel', link: function(scope, elm, attrs, ctrl) { function formatter(value) { return dateFilter(value, 'yyyy-MM-dd'); //format } function parser() { return ctrl.$modelValue; } ctrl.$formatters.push(formatter); ctrl.$parsers.unshift(parser); } };}]);
HTML
<input type="text" ng-model="start_date" date-format disabled="disabled">
Display Effect. You can modify the format in the Code by formatting it.
Why is Angularjs so popular?
If other friends have good originals or translations, try to recommend them to bole online. In this article, let's gradually find out why angular is so popular: Angular. js is a MV * (Model-View-Whatever, whether it is MVC or MVVM, unified by model Drive View) JavaScript framework, it is the SPA (single-page-application) application Framework launched by Google, which adds a lot of magic changes to our web application development. I can spend the whole day telling you why you have to try angular. js in a new project, but I think it's still a bit difficult to say. Data Binding and scopes (scope) are the first problems that emerge first: does angular support data binding? Next let's take a look at angular. js Data Binding:
Edit in plucker Insert your name: Echo: {user. name} in this code snippet, before explaining the details, I still want to try it out: Note: Do not be too anxious to understand ng-app at the moment. As you can see, what I input in input will be displayed in the back echo. How does this work? In short, angular ng-model (