Angular 在创建组件之前调用Subscriber.next()-最佳做法?

Angular 在创建组件之前调用Subscriber.next()-最佳做法?,angular,rxjs,Angular,Rxjs,假设我有这个模板 sample.component.html: <div *ngFor="let contact of contacts"> <my-contact-card [contact]="contact"></my-contact-card> </div> 这段代码 sample.component.ts export class SampleComponent implements OnInit { contacts:

假设我有这个模板

sample.component.html:

<div *ngFor="let contact of contacts">
   <my-contact-card [contact]="contact"></my-contact-card>
</div>

这段代码

sample.component.ts

export class SampleComponent implements OnInit {
   contacts: Subject<Contact>;
   constructor(private _contactsService: ContactsService) {
      ...
   }

   ngOnInit() {
      this._contactsService.getAll().subscribe(contact => {
         <do something with contact>
         this.contacts.next(contact);
   }
}
导出类SampleComponent实现OnInit{
联系人:受试者;
构造器(专用联系人服务:联系人服务){
...
}
恩戈尼尼特(){
这是._contactsService.getAll().subscribe(contact=>{
this.contacts.next(contact);
}
}
当然,在
ContactCardComponent
中有一个订阅
ngOnInit
中的
contacts
,因为这是一个
@Input()
参数。是的,我知道,这个例子感觉有点奇怪,只是为了说明问题

但是,问题是,在发布第一个
联系人
后会调用
ContactCardComponent
的构造函数,因此只有第二个和所有后续值到达组件,第一个值会丢失

我甚至可以将
SampleComponent
的订阅移动到
ngAfterViewInit
,没关系,
ContactCardComponent
仍然迟到

当然,我可能会求助于使用
BehaviorSubject
,但这在某种程度上让人感觉不舒服,而且我还必须在订阅之前提供一些起始值(明显的候选者:
null
,然后必须再次检查订阅方的代码内部,这更糟糕)

在这种情况下,最佳做法是什么