0

Hi I can't get opaquetoken to work, did I overlooked anything?

Plunk

in app.ts

export const SbToken = new OpaqueToken('myToken');
const testfile = 'Hello';

in ngModule

providers: [{provide:SbToken, useValue:testfile}]

in test.cmp

constructor(@Inject(SbToken) private token) {
      console.log(token)
    }

and i'm getting error (in punker, which uses systemJS i guess)

(SystemJS) Error: Can't resolve all parameters for TestComponent: (?).

within my webpack Project I get similar error

Can't resolve all parameters for LoginPage: (NavController, SelfbitsAngular, ?).
Han Che
  • 8,239
  • 19
  • 70
  • 116
  • Did you import the `SbToken` in `test.cmp`? – Günter Zöchbauer Sep 02 '16 at 09:11
  • Seems I have some blue deficiency. I never see the Plunker links if they are not highlighted in some way. Sorry for that. The problem doesn't seem to be related to `OpaqueToken`. If you make it optional `(@Optional() @Inject(SbToken)` or inject `private service:TestService)` it fails the same. If you move the component to the same file as the module then it's working fine. http://plnkr.co/edit/lHIuc81COVEGv4SKGOKd?p=preview. I don't know exactly what causes the problem though. – Günter Zöchbauer Sep 02 '16 at 10:21
  • but that kinda ruins the use of opaqueToken, doesn't it? If I can't export them for usage... – Han Che Sep 02 '16 at 12:05
  • As I said the problem is not related to `OpaqueToken` at all. It seems to be some kind of import problem. As mentioned if you don't use `OpaqueToken` but inject something else by type you get the same error. – Günter Zöchbauer Sep 02 '16 at 12:07

1 Answers1

2

You have a cyclic dependency between app.module and test.component. This problem was already answer in angular 2 OpaqueToken

Community
  • 1
  • 1
Fernando
  • 2,131
  • 3
  • 27
  • 46