Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$inject in strictdi with ngMetadata services #221

Open
rubenCodeforges opened this issue May 22, 2018 · 3 comments
Open

$inject in strictdi with ngMetadata services #221

rubenCodeforges opened this issue May 22, 2018 · 3 comments

Comments

@rubenCodeforges
Copy link

First for all thanks for the hard work , unfortunate i didnt found any mentions in the docs or closed issues.

So the question is very simple:

someOldController.$inject = [] // this is required in stricDi
someOldController(UserServiceCreatedWithNgMetadata) {
}

the question is ,d how do i provide the ngMetadata created service in $inject ? Ive tried with string 'UserServiceCreatedWithNgMetadata' not found , ive tried with UserServiceCreatedWithNgMetadata not found , ive tried with UserServiceCreatedWithNgMetadata.name same story.

another example is httpInterceptor

@Injectable()
export class AuthInterceptor implements IHttpInterceptor {
    static factory(auth: AuthService): RequestInterceptor {
        return new AuthInterceptor(auth);
    }
    
    constructor(auth: AuthService) {
        console.log(auth);
    }

    response(response: any): any {
        console.log(response);
        return response;
    }
}



httpConfigFactory.$inject = ['$httpProvider'];
export function httpConfigFactory($httpProvider: any): any {
    $httpProvider.interceptors.push(AuthInterceptor.factory);
}

In the interceptor example i will get a strictDi error aswell

@rubenCodeforges
Copy link
Author

even more , if i try to inject via class propperty :
@Inject(AuthService) getAuth: AuthService;

i will get an error

VM88192:64 Uncaught TypeError: Cannot read property '$inject' of undefined
    at InjectMetadata.paramDecoratorForNonConstructor 

@aciccarello
Copy link
Collaborator

If I remember correctly, you'd want to do something like $inject = [getInjectableName(AuthService)].

@rubenCodeforges
Copy link
Author

@aciccarello Yep that works , thanks.
That should be somewhere in the docs , because sometimes you cant take a huge app and just rewrite it all , in terms of backwards compatibility you are forced to do it in progression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants