AngularJS Filter with TypeScript and injection

后端 未结 4 1061
没有蜡笔的小新
没有蜡笔的小新 2021-01-12 15:26

Can somebody provide me with an example of how I can create an Angular Filter in TypeScript that uses dependency injection. At the bottom is what I currently have, which is

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-12 15:36

    You can use classes to inject dependencies, just use the [] in the module and use method injection as below:

    module Filters {
        export class MyFilter {
            public static Factory(injectableService: InjectableService) {
                return function (input:any) {
    
                    // use injectableService to affect your input in desired way
    
                    return input;
                }
            }
        }
    
        angular.module('app')
            .filter('myFilter', ['injectableService', MyFilter.Factory]);
    

提交回复
热议问题