First of all if this is horrible design, I'm more than happy to change.
In my index.html
I, in the body, have:
<month [year]="2016" [monthOfYear]="4">Loading...</month>
month.component.ts
is then:
import { Component, Input, OnInit } from '@angular/core';
import { DayComponent } from '../day/day.component';
import * as Models from '../../../models/_models';
@Component({
selector: 'month',
moduleId: module.id,
templateUrl: 'month.component.html',
styleUrls: ['month.component.css'],
directives: [DayComponent]
})
export class MonthComponent {
name: string;
days: Models.Day[];
@Input('year') year: number;
@Input('monthOfYear') monthOfYear: number;
month: Models.Month;
ngOnInit() {
this.month = new Models.Month(this.year, this.monthOfYear);
this.name = this.month.getMonthName();
this.days = this.month.days;
}
}
...And ngOnInit()
is called correctly. However at the time of calling (or perhaps ever, but I don't know how to determine that) both year
and monthOfYear
are undefined
.
How do I ensure the values are passed in at ngOnInit()
, or is there a better pattern to accomplish this?