My directive is functioning correctly when the application is not minified
However, when I minify it, an error occurs
Unknown provider: tProvider <- t <- dateTimeFilterDirective
Is there a way to ensure the directive works even when minified?
module bundledAppModule {
'use strict';
export class ngDateTimeFilterDirective implements ng.IDirective {
static $inject = ['$filter'];
// static $inject = ['$scope', '$element', '$attrs', '$ngModel', '$filter'];
public static className = 'dateTimeFilter';
public restrict: string;
public require: string;
public priority: number;
public link: ng.IDirectiveLinkFn;
constructor($filter: ng.IFilterService) {
this.restrict = 'A';
this.require = 'ngModel';
this.priority = 1;
this.link = ($scope: ng.IScope, $element: JQuery, $attrs: any, $ngModel: ng.INgModelController) => {
$ngModel.$formatters.push((modelValue) => {
console.log('ngDateTimeFilterDirective', modelValue);
return new Date($filter('date')(modelValue, 'medium'));
});
};
}
public static factory(): ng.IDirectiveFactory {
var directive = ($filter: ng.IFilterService) => {
return new ngDateTimeFilterDirective($filter);
};
return directive;
}
};
}
UPDATE:
The error is related to the dependency $filter: ng.IFilterService. Removing it allows the directive to work in both minified and unminified versions. However, I need the filter and am unsure how to make it function after minification. I understand that for controllers, specifying dependencies twice is necessary for them to work after minification, so perhaps a similar approach is needed for directives.
Here is the stack trace - minified :-) https://i.sstatic.net/PkuyF.png
This is how the directive is implemented:
<div ng-app="bundledApp" ng-controller="bundledController">
<input type="datetime-local" ng-model="someDate" date-time-filter />
{{someDate}}
<input type="button" ng-click="setDate();" value="changedate">
</div>
The error occurs during initialization of the app. While the controller action is triggered on button click, the directive is not executed (no console log message appears)