How can I define an AngularJS factory using TypeScript class that has constructor parameters

前端 未结 6 823
北恋
北恋 2020-12-30 01:53

I want to write a TypeScript class that gets a \"prefix\" parameter in the constructor, this class also needs access to a LogService inject.

Using plain JavaScript y

6条回答
  •  时光说笑
    2020-12-30 02:28

    this is how i do it

     namespace app {
                 let app =angular.module('foo',[]);
                   app.factory(factories);//for registering whatever is there in factories namespace
    
          }
    
     namespace app.factories {
    
    
     export class fooFactory {
    
        static $inject = ['fooHelperService']
        constructor(fooHelperService: services.fooHelperService) {
    
            return {
    
                fooFunc: () => {
    
                   return 'hellow world'
                }
            }
        }
     }
    
    }
    

提交回复
热议问题