Skip to content Skip to sidebar Skip to footer

AngularJS App: How Can I Fetch Date From The View And Use It In The Controller?

I am working on an app in AngularJS 1.6, using the Giphy.com api. The view displays, among others, an 'import date'. The parameter import_datetime comes from the API and is item-sp

Solution 1:

You can create a custom filter that will parse a date from giphy format to a JavaScript date object and pipe it to the AngularJS built-in date filter:

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

app.filter('dateParse', function() {
  return function(date) {
    return Date.parse(date);
  };
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="app">
  <p>{{'2019-07-10 14:12:59' | dateParse | date : "dd.MM.y"}}</p>
</div>

Post a Comment for "AngularJS App: How Can I Fetch Date From The View And Use It In The Controller?"