English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
I filtri integrati di Angularjs (filter) offrono funzionalità molto potenti per la formattazione delle informazioni dei nostri dati, come: formattazione dell'ora, della data, formattazione della precisione numerica, localizzazione linguistica, formattazione della moneta, ecc. Tuttavia, questi filtri generalmente vengono utilizzati nella VIEW, ad esempio, il codice della vista per la formattazione dell'ora/data:
<div ng-app> <p> Seleziona una data <input type="date" id="date" ng-model="datevalue" /> </p> <p> {{ datevalue | date : 'fullDate'}} </p> </div>
So the question is, if I need to use the filter to format the date/time in the js code of the controller (controller), how should I deal with it? Let's directly show the code: View (view) template code:
<div ng-app="dateApp" ng-controller="dateController"> <p> {{ result }} </p> </div>
Controller (controller) code:
var app = angular.module('dateApp', []); app.controller( 'dateController', function ($scope, $filter) { $scope.result = $filter('date')(new Date(), 'fullDate'); } ;
This is the implementation of formatting date/time using the filter ($filter) in the js code of the controller (controller.js). I hope it will be helpful to everyone's learning, and I also hope everyone will support the Shouting Tutorial more.
Declaration: The content of this article is from the network, the copyright belongs to the original author, the content is contributed and uploaded by Internet users spontaneously, this website does not own the copyright, does not undergo manual editing, nor bear relevant legal liability. If you find any content suspected of copyright infringement, please send an email to: notice#oldtoolbag.com (when sending an email, please replace # with @) for reporting, and provide relevant evidence. Once confirmed, this site will immediately delete the content suspected of infringement.