angular-docs-cn/aio/content/examples/pipes/src/app/hero-birthday2.component.ts
Nick Hodges f954ab6f10 docs: add note about the month being zero-based in the Date constructor (#37770)
Because the month is zero based, it may confuse some users that '3'
is in fact 'April'. This comment should clear that up.

PR Close #37770
2020-06-26 09:55:18 -07:00

21 lines
622 B
TypeScript

// #docregion
import { Component } from '@angular/core';
@Component({
selector: 'app-hero-birthday2',
// #docregion template
template: `
<p>The hero's birthday is {{ birthday | date:format }}</p>
<button (click)="toggleFormat()">Toggle Format</button>
`
// #enddocregion template
})
// #docregion class
export class HeroBirthday2Component {
birthday = new Date(1988, 3, 15); // April 15, 1988 -- since month parameter is zero-based
toggle = true; // start with true == shortDate
get format() { return this.toggle ? 'shortDate' : 'fullDate'; }
toggleFormat() { this.toggle = !this.toggle; }
}