How to use embedded services in static methods

I want to use angularjs and typescript together. I am trying to create Orm factoryusing typescript and style with some problem.

I defined the factory class as follows:

class OrmModel implements IOrmModel {
    static $inject = ['$http', '$q', 'config'];

    private name:string;
    private isNewRecord:boolean = false;

    constructor(public $http:ng.IHttpService, private $q:ng.IQService, private config:Object) {
        //...
    }

    static findAll(params:ISearchParams, relations:string[]):ng.IPromise<OrmModel> {
        //...
    }
}

Here I defined a factory.

OrmModule:ng.IModel = angular.module('core.orm', []);
OrmModule.factory('OrmModel', ['$http', '$q', OrmModel]);

How to use the method $httpor $qin findAll()?

+4
source share
1 answer

To live in angular ecosystems, there must be services. Therefore, move the function findAllto your own service. Thus, he may have access to other services, such as $httpand $q.

+1
source

All Articles