0

In the angular 2 examples for pipe: https://angular.io/docs/ts/latest/guide/pipes.html there is an example of HeroBirthday2Component. I am not able to understand how this line works

get format() { return this.toggle ? 'shortDate' : 'fullDate'; }

I mean I understand that it toggles the format property and the DOM gets updated with the change detection after toggleFormat() changes it. But I am not able to grasp the line above. Could some one please explain the code line and its implementation.

Pawan
  • 63
  • 6
  • What don't you understand, the `return this.toggle ? 'shortDate' : 'fullDate';` part? – tymeJV May 17 '17 at 20:35
  • no the get statement.. I don't see any calls for a function named get or format() or is get a keyword? – Pawan May 17 '17 at 20:36

1 Answers1

0

That's a getter, just like in other strongly typed languages.

See here:

get and set in TypeScript

Community
  • 1
  • 1
chrispy
  • 3,552
  • 1
  • 11
  • 19