错误的数据传递给Angular2中的组件

时间:2016-06-09 13:29:47

标签: typescript angular

我在父组件中嵌套了两次组件

<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();
        }
}

1 个答案:

答案 0 :(得分:0)

在发送给子组件之前,您必须确保将selectedDate转换为Date DataType