I just create a filter to convert my date to time. And I would call in the official filter "date" of AngularJS.
project.date_created_at
and project.mel
don't have the same format. So I need to create a custom filter for project.date_created_at
.
HTML :
<span>{{ project.date_created_at | dateCustom }}</span>
<span>{{ project.mel | date:'dd/MM/yyyy' }}</span>
JS :
myApp.filter('dateCustom', function () {
return function (input) {
if(input != undefined) {
var d = new Date(input);
var time = d.getTime();
// use official $filter('date') here ?
}
}
});
I would like to use this format :
date:'dd/MM/yyyy'
Answer: A is the correct option. The syntax of applying multiple filters in AngularJS can be written as: {{ expression | filter1 | filter2 | ... }}
In AngularJS, you can also inject the $filter service within the controller and can use it with the following syntax for the filter. Syntax: $filter("filter")(array, expression, compare, propertyKey) function myCtrl($scope, $filter) { $scope. finalResult = $filter("filter")( $scope.
Which of the below is an Invalid filter in AngularJs? Explanation: The filter in angular is provide transformation of the data Email is an invalid filter in Angular JS the valid filter are JSON, limitTo, and order by.
What of the following is the correct way for applying multiple filters in AngularJS ? Explanation: The correct syntax for applying the multiple filters is{{ expression | filter1 | filter2}}.
You can inject $filter as a dependency like you would do it for a controller, a service or a directive.
myApp.filter('myFilter',[ '$filter', function ($filter) {
return function (input) {
/**
Do your stuff
**/
return $filter('date')(myDate,myFormat);
}
}]);
On a side note, you should use angular.isDefined instead of != undefined
.
See the documentation of $filter and of date for more details
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With