我在父组件中嵌套了两次组件
<day-selector [SelectedDate]="selectedDate" (onDayChange)="onDateChangebyChild($event)" ></day-selector>
<day-selector [SelectedDate]="selectedDate" (onDayChange)="onDateChangebyChild($event)" ></day-selector>
(两者都相同)
并在day-selector.component.template.html中输出“SELECTED DATE”
<input type="text" [(ngModel)]="SelectedDate" />
由于某种原因,他们打印不同的数据。为什么会这样?
这是DaySelector组件:
@Component({
selector: 'day-selector',
templateUrl:'app/shared/day-selector/day-selector.component.html'
})
export class DaySelectorComponent implements OnInit{
@Input() SelectedDate: Date;
@Output() onDayChange: EventEmitter<any>;
constructor() {
this.onDayChange = new EventEmitter();
}
}
答案 0 :(得分:0)
在发送给子组件之前,您必须确保将selectedDate
转换为Date DataType
。