Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the effect of adding '$' dollar sign infront of event in Angular?

What is the effect of adding '$' dollar sign infront of event in Angular?

onModelUpdated($event: any) {
    console.log($event);
  }

vs

onModelUpdated(event: any) {
    console.log(event);
  }
like image 296
Anthony Avatar asked Dec 08 '22 11:12

Anthony


1 Answers

$ prefix in variable names has no any kind of an effect. 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.

Specifically when it comes to $event and its use in Angular, it is more of a convention carried over from the days of AngularJS. In AngularJS, internal variables exposed by the framework were prefixed with a $.

That is why sometimes you see event and other times $event.

There was a proposal to get rid of it, but nothing happened.

So it is more of a question of style and conventions, and it is up to the personal/project preferences to come up with a convention about whether to use $event or event.

like image 162
ulmas Avatar answered Jun 14 '23 17:06

ulmas