Functional directives TS

This commit is contained in:
Mo Bitar
2020-04-13 08:27:10 -05:00
parent 38873afa43
commit aed8d4a3da
15 changed files with 138 additions and 120 deletions

View File

@@ -0,0 +1,24 @@
/* @ngInject */
export function lowercase() {
return {
require: 'ngModel',
link: function (
scope: ng.IScope,
_: JQLite,
attrs: any,
ctrl: ng.IController
) {
const lowercase = (inputValue: string) => {
if (inputValue === undefined) inputValue = '';
const lowercased = inputValue.toLowerCase();
if (lowercased !== inputValue) {
ctrl.$setViewValue(lowercased);
ctrl.$render();
}
return lowercased;
};
ctrl.$parsers.push(lowercase);
lowercase((scope as any)[attrs.ngModel]);
}
};
}