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

Component inheritance and @ViewChildren or @ContentChildren: "Uncaught Error: useExisting is unimplemented"

giancarlo-dm opened this issue · comments

Hello,

First I appreciate the hardwork you guys had put on this project.

The problem:

I was trying to implement a use case similar to this stackoverflow question, but when I tried to use the provider declaration: providers: [{provide: BaseComponent, useExisting: forwardRef(() => ChildComponent2) }], I got the following error on the console:

Uncaught Error: useExisting is unimplemented
    at resolveReflectiveProvider (modules.js?hash=30556e0263a3949b7bc00058f573ce0b4384bd92:62054)
    at modules.js?hash=30556e0263a3949b7bc00058f573ce0b4384bd92:62121
    at Array.forEach (<anonymous>)
    at Object._normalizeProviders (modules.js?hash=30556e0263a3949b7bc00058f573ce0b4384bd92:62111)
    at _bundleComponent (modules.js?hash=30556e0263a3949b7bc00058f573ce0b4384bd92:62379)
    at modules.js?hash=30556e0263a3949b7bc00058f573ce0b4384bd92:62402
    at Array.forEach (<anonymous>)
    at bundle (modules.js?hash=30556e0263a3949b7bc00058f573ce0b4384bd92:62401)
    at modules.js?hash=30556e0263a3949b7bc00058f573ce0b4384bd92:62429
    at Array.forEach (<anonymous>)

So I browsered the source code and found this at src/core/di/reflective_provider.ts:

if (provider.useExisting) {
    const [name,value] = provide( provider.useExisting );
    const method = 'factory';

    throw new Error('useExisting is unimplemented');
    // target = (v) => v;
    // annotate(target, 'factory', {name});
    // annotate(target, 'inject', [toInjectorName(provider.useExisting)]);
  }

The questions:

Was it too hard to backport this functionality or it was just forgotten to implement?

Is there an workaround (or correct way of doing this), that is similar to the stackoverflow example I gave?