我对我的简单服务做错了,但我无法理解。
app.component.ts
import { MeetingService } from '../../shared/services/meeting.service';
@Component({
viewProviders: [MeetingService],
})
meetingService.ts
@Injectable();
export class MeetingService {
constructor(private http: Http) {}
getList() {
return this.http.get('../fake-data/meetingList.json')
.map(response => response.json());
}
}
meetingList.component.ts
import { MeetingService } from '../../shared/services/meeting.service';
@Component({
viewProviders: [HTTP_PROVIDERS, MeetingService],
})
export class MeetingListComponent {
private meetingList: any;
constructor(private meetingService: MeetingService) {}
getList() {
this.meetingService.getList().subscribe(
data => { this.meetingList = data; },
err => console.error(err),
() => console.log('done loading meeting list')
);
}
ngOnInit() {
this.getList();
}
}
错误
EXCEPTION: Cannot resolve all parameters for 'MeetingService'(?). Make sure that all the parameters are decorated with Inject or have valid type annotations and that 'MeetingService' is decorated with Injectable.
有人可以看一下吗?谢谢。
答案 0 :(得分:2)
在;
@Injectable()
@Injectable()
export class MeetingService {
constructor(private http: Http) {}
getList() {
return this.http.get('../fake-data/meetingList.json')
.map(response => response.json());
}
}
答案 1 :(得分:0)
您没有显示引导代码 - 您是否在引导期间向应用程序提供商添加了Http
,例如
bootstrap(App, [HTTP_PROVIDERS])