假设我有一个访问父路线的组件,如下所示:
ngOnInit() {
this.sub = this.route.parent.parent.parent.params.subscribe(params => {
this.siteId = params["siteId"];
this.loadContents();
this.loadTypes(this.siteId);
});}
我为父路线提供假值:
providers: [
SiteService,
UserService,
Modal,
Overlay,
{
provide: ActivatedRoute,
useValue: { parent: { parent: { parent: { 'params': Observable.from([{ 'siteId': '156' }]) } } } },
},
OverlayRenderer,
AuthHttp,
MessageService,
],
它给了我以下错误:
失败:无法读取属性' undefined'未定义的
AT line:
useValue:{parent:{parent:{parent:{' params&#39 ;: Observable.from([{' siteId':' 156'}]) }}},
请告诉我我正在做的是什么。 我引用了以下链接:
How to mock an activatedRoute parent Route, Testing Angular 2 parent route