ngParty / ng-metadata

Angular 2 decorators and utils for Angular 1.x

Home Page:https://hotell.gitbooks.io/ng-metadata/content/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

$inject in strictdi with ngMetadata services

rubenCodeforges opened this issue · comments

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

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 

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

@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.