Parent and children communicate via a service example from the official guide on Angular.io makes use of dollar signs in Observable stream names.
Notice missionAnnounced$
and missionConfirmed$
in the following example:
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);
}
}
Can anyone explain:
$
is used? What's the reason behind this notation? Do I always need to use this for public properties?$ suffix (popularized by Cycle.js) is used to indicate that the variable is an Observable. It could make it to the official style guide too but it's not there yet.
An Observable is a stream of values emitted over time. In code, it is often represented with the dollar sign $ as a suffix. For example, by using the fromEvent operator, we can create an observable that listen to changes to a DOM element element on input events.
A $ dollar sign in JavaScript (and TypeScript by extension) is a valid identifier to use as part of a variable name, it carries no syntactical meaning. It can be used in the beginning, middle or end of a variable/function name.
In Finnish-Goldman notation, what you do is pluralize observable variable names with a unicode character that matches the last letter of the pluralized word. For example: const oxeÑ = Observable. from(olleyOlleyOxenStream()); const mic€ = Observable.
$ suffix (popularized by Cycle.js) is used to indicate that the variable is an Observable. It could make it to the official style guide too but it's not there yet
Read more here : What does the suffixed dollar sign $
mean?
Update: Read more about the trailing “$” sign on Angular website here: https://angular.io/guide/rx-library#naming-conventions-for-observables
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With