ngParty / ng-metadata

Angular 2 decorators and utils for Angular 1.x
https://hotell.gitbooks.io/ng-metadata/content/
MIT License
355 stars 46 forks source link

$inject in strictdi with ngMetadata services #221

Open rubenCodeforges opened 6 years ago

rubenCodeforges commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

rubenCodeforges commented 6 years ago

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