一个常见的错误消息:error NG2003 - No suitable injection token for parameter
构造函数里有个参数类型为string:
constructor(@Inject('apiUrl') private myname) {
console.log('Jerry inject: ' + myname);
}
这个myname通过注解@Inject修饰,id为apiUrl.
谁负责注入apiUrl呢?在app module里:
providers: [{ provide: JerrySandBoxService },
{ provide: GreetingService, useClass: EnglishGreetingService},
{
provide: 'apiUrl',
useValue: 'http://localhost:4200/heros'
}],
运行时:
网友评论