0

This is how I currently do it:

class AService {
    $http: any;
    $state: any;
    static $inject = ['$http', '$state'];
    constructor($http, $state) {
        this.$http = $http;
        this.$state = $state;
    };

It becomes alot of boilerplate code to satisfy typescript. Is there any shorter way?

1 Answer 1

1

You can specify that the parameters should be stored as fields directly in the constructor.

class AService {
    static $inject = ['$http', '$state'];
    constructor(private $http, private $state) {
    }
}

You could also specify the injection parameter array ($inject) when you register the type with the angularjs module and remove $inject from the class.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.