通过@Input 参数传递日期不会影响角度材料日期范围选择器中的 [max] 指令

问题描述 投票:0回答:1

当通过 @Input 将日期传递给 [max] 指令时,日期选择器不会对传递的值做出反应。

下面的组件代码

@Component({
  selector: 'range-picker',
  templateUrl: 'range-picker.component.html',
  styleUrls: ['range-picker.component.css'],
  encapsulation: ViewEncapsulation.None
})
export class RangePickerComponent {
  @Input() maxDate: Date;
 
}

模板

  <mat-date-range-input [formGroup]="range" [rangePicker]="picker" [max]="maxDate">

以及父组件和视图:

<range-picker [maxDate]="maxDate"></range-picker>
public maxDate: new Date();

有人知道问题出在哪里吗?

angular angular-material angular-material2
1个回答
0
投票

maxDate 的值以字符串形式出现,因此请使用

<range-picker [maxDate]="'maxDate'"></range-picker>
© www.soinside.com 2019 - 2024. All rights reserved.