One challenge I'm facing involves using a REST API to retrieve date formatting information that is crucial for my custom date filter in Angular. My goal is to seamlessly integrate this date format into my view by utilizing the filter.
In my view, I have implemented something along these lines:
<span>{{vm.filters.fromDate | dateFilter}}</span>
The structure of my filter looks like this:
.filter('dateFilter', function( $filter, commonService ) {
var dateFormat = commonService.getDateFormat();
return function( inputDate ) {
return $filter('date')( inputDate, dateFormat );
};
})
Additionally, there is a method within commonService called
commonService.setDateFormat( dateFormat )
, which is triggered upon successful completion of the REST call.
However, I am encountering an issue where the filter processes before the API response is received, resulting in an incorrect date format being displayed on the UI due to the inability to retrieve the correct format through commonService.getDateFormat()
.
I am seeking advice on the most effective approach to execute or load an Angular filter upon the success of a task or the broadcast of an event.