简体   繁体   中英

Angular2: Can't inject service into service

So here is my code, I do believe you can understand what I'm trying to accomplish with no additional explanations.

@Injectable()
export class Dispatcher {
}

@Injectable()
export class TodoStore {

    constructor(@Inject(Dispatcher) private dispatcher:Dispatcher){ 

    }
}

@Component({
    ...
      providers:[TodoStore,Dispatcher]
}
export class MyComponent{
    costructor(@Inject(TodoStore) private store:TodoStore) {}
}

I'm getting Uncaught Error: Can't resolve all parameters for TodoStore: (?). Any ideas, please

This should work, and it works for me. It is not possible to say why it doesn't work in your case, without the complete code and setup.

Two comments: constructor was misspelled, and @Inject(...) is unneeded.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM