【发布时间】:2018-11-17 04:28:47
【问题描述】:
我正在尝试使用 Angular Route Resolve 在激活路由之前获取组件数据。
我看到的所有示例都调用服务中的一个方法并返回,我在服务中有 5 个不同的方法需要调用 b4 组件被激活。
下面是我想要实现的示例,ContactService 有 3 个方法都需要调用 - 我怎样才能在一次调用中返回所有 3 个方法?
任何指针表示赞赏。
Contact-Resolver.ts - 下面
import { Injectable } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot } from '@angular/router';
import { ContactsService } from './contacts.service';
@Injectable()
export class ContactResolve implements Resolve<Contact>
{
constructor(private contactsService: ContactsService) {}
resolve(route: ActivatedRouteSnapshot)
{
return this.contactsService.getContact(route.paramMap.get('id')); //method in Service
}
// return this.contactsService.getCities(); //Another method in Service that also needs to be called
// return this.contactsService.getAllParts(); //Another method in Service that also needs to be called
}
【问题讨论】:
-
方法返回什么?可观察的?
-
@martin 是的,他们返回 Observables
标签: angular rxjs angular5 angular4-router