Yogesh Nikam
Yogesh Nikam

Reputation: 533

Variable with $ prefix in angular

I came across the scenario in Angular 11 where the variable is declared with $ symbol.

e.g. $testVar = new Subject<Type[]>(this.name);

What is the meaning of this declaration with $ symbol?

Upvotes: 0

Views: 1816

Answers (1)

Lukasz Gawrys
Lukasz Gawrys

Reputation: 1334

It does not have any special function in TypeScript but there is a convention of using $ symbol in the name of the variable which stores an Observable. As Subject would create an Observable it might be used for this purpose here.

However the more common version of this is to use $ as suffix like this testVar$ - seeing that I would expect an Observable to be stored there.

But I would not use this suffix for variable storing the subject but rather the final Observable.


testSubject = new Subject<Type[]>(this.name);
test$ = testSubject.asObservable();

Upvotes: 2

Related Questions