来自Angular.io官方指南的父节点和子节点通过服务示例进行通信在Observable流名称中使用了美元符号。
注意下面例子中的missionAnnounced$
和missionConfirmed$
:
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs';
@Injectable()
export class MissionService {
// Observable string sources
private missionAnnouncedSource = new Subject<string>();
private missionConfirmedSource = new Subject<string>();
// Observable string streams
missionAnnounced$ = this.missionAnnouncedSource.asObservable();
missionConfirmed$ = this.missionConfirmedSource.asObservable();
// Service message commands
announceMission(mission: string) {
this.missionAnnouncedSource.next(mission);
}
confirmMission(astronaut: string) {
this.missionConfirmedSource.next(astronaut);
}
}
谁能解释一下:
$
?这个符号背后的原因是什么?公共物品总是需要用这个吗?