material-component-datetime-picker-您提供了 'undefined' 预期流的位置。您可以提供 Observable、Promise、Array 或 Iterable
material-component-datetime-picker-You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable
我已尝试根据文档和以下包含有关环境的信息使用 material-component-datetime-picker。
Angular
Angular 版本:10.1.0
material 版本:10.1.0
angular-material-components/moment-adapter - 4.0.1
angular-material-components/datetime-picker - 4.0.2
以下是查看日期时间选择器的代码块。
<mat-form-field> <input matInput [ngxMatDatetimePicker]="picker" placeholder="Choose a date" [formControl]="tab._from" [min]="minDate" [max]="maxDate" [disabled]="disabled"> <mat-datepicker-toggle matSuffix [for]="picker"> </mat-datepicker-toggle> <ngx-mat-datetime-picker #picker [showSpinners]="showSpinners" [showSeconds]="showSeconds" [stepHour]="stepHour" [stepMinute]="stepMinute" [stepSecond]="stepSecond" [touchUi]="touchUi" [color]="color"> </ngx-mat-datetime-picker> </mat-form-field>
当我尝试加载页面时,日期时间选择器出现,但控制台出现以下错误。
ERROR TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable. at subscribeTo (subscribeTo.js:27) at subscribeToResult (subscribeToResult.js:11) at MergeMapSubscriber._innerSub (mergeMap.js:59) at MergeMapSubscriber._tryNext (mergeMap.js:53) at MergeMapSubscriber._next (mergeMap.js:36) at MergeMapSubscriber.next (Subscriber.js:49) at Observable._subscribe (subscribeToArray.js:3) at Observable._trySubscribe (Observable.js:42) at Observable.subscribe (Observable.js:28) at MergeMapOperator.call (mergeMap.js:21)
TS 文件
export class Picker {
@ViewChild('fromPicker') fromPicker: any;
@ViewChild('toPicker') toPicker: any;
public date: moment.Moment;
public disabled = false;
public showSpinners = true;
public showSeconds = false;
public touchUi = false;
public enableMeridian = false;
public minDate: moment.Moment;
public maxDate: moment.Moment;
public stepHour = 1;
public stepMinute = 1;
public stepSecond = 1;
public color: ThemePalette = 'primary';
public stepHours = [1, 2, 3, 4, 5];
public stepMinutes = [1, 5, 10, 15, 20, 25];
public stepSeconds = [1, 5, 10, 15, 20, 25];
}
似乎错误与我们使用的选择器有关。
有什么原因或缺少依赖项吗?
首先,您使用的是 ngx-mat-datetime-picker,它是 angular material 日期选择器的包装插件:
https://www.npmjs.com/package/ngx-mat-datetime-picker
实现看起来不错,但一定会出现错误,因为您没有在属性中传递具有正确类型的预期值。您要传递给属性的某些组件 属性 未定义。
您可以重新访问演示实现并检查您是否发送了正确的值:
https://stackblitz.com/edit/demo-ngx-mat-datetime-picker?file=src%2Fapp%2Fapp.component.html
将@angular-material-components/datetime-picker 更新到版本 4.0.3 对我有用。
几个小时前发布了更新
https://www.npmjs.com/package/@angular-material-components/datetime-picker
在版本 4.0.3 中也适用于我。更新您的包裹。
我遇到了同样的问题
Angular11.1.0
Material11.1.0
日期时间选择器:5.0.3
我已经设法在一定程度上隔离了问题,它发生在这里:
_watchStateChanges() {
const datepickerStateChanged = this.datepicker ? this.datepicker.stateChanges : of();
const inputStateChanged = this.datepicker && this.datepicker.datepickerInput ?
this.datepicker.datepickerInput.stateChanges : of();
const datepickerToggled = this.datepicker ?
merge(this.datepicker.openedStream, this.datepicker.closedStream) :
of();
this._stateChanges.unsubscribe();
this._stateChanges = merge(this._intl.changes, datepickerStateChanged, inputStateChanged, datepickerToggled).subscribe(() => this._changeDetectorRef.markForCheck());
}
出于某种原因,此处未定义 datepickerStateChanged。这就是导致问题进一步发展的原因。还不知道为什么。如果有人有更多的答案,那就太棒了。现在,我要将此作为错误归档。
似乎已经在里面了:
https://github.com/h2qutc/angular-material-components/issues/94
他们建议降级到 4.0.3,这是我明天要尝试的。
对于 angular v11 将 @angular-material-components/datetime-picker 升级到 v 5.1.0 修复了这个错误
我已尝试根据文档和以下包含有关环境的信息使用 material-component-datetime-picker。
Angular
Angular 版本:10.1.0
material 版本:10.1.0
angular-material-components/moment-adapter - 4.0.1
angular-material-components/datetime-picker - 4.0.2
以下是查看日期时间选择器的代码块。
<mat-form-field> <input matInput [ngxMatDatetimePicker]="picker" placeholder="Choose a date" [formControl]="tab._from" [min]="minDate" [max]="maxDate" [disabled]="disabled"> <mat-datepicker-toggle matSuffix [for]="picker"> </mat-datepicker-toggle> <ngx-mat-datetime-picker #picker [showSpinners]="showSpinners" [showSeconds]="showSeconds" [stepHour]="stepHour" [stepMinute]="stepMinute" [stepSecond]="stepSecond" [touchUi]="touchUi" [color]="color"> </ngx-mat-datetime-picker> </mat-form-field>
当我尝试加载页面时,日期时间选择器出现,但控制台出现以下错误。
ERROR TypeError: You provided 'undefined' where a stream was expected. You can provide an Observable, Promise, Array, or Iterable. at subscribeTo (subscribeTo.js:27) at subscribeToResult (subscribeToResult.js:11) at MergeMapSubscriber._innerSub (mergeMap.js:59) at MergeMapSubscriber._tryNext (mergeMap.js:53) at MergeMapSubscriber._next (mergeMap.js:36) at MergeMapSubscriber.next (Subscriber.js:49) at Observable._subscribe (subscribeToArray.js:3) at Observable._trySubscribe (Observable.js:42) at Observable.subscribe (Observable.js:28) at MergeMapOperator.call (mergeMap.js:21)
TS 文件
export class Picker {
@ViewChild('fromPicker') fromPicker: any;
@ViewChild('toPicker') toPicker: any;
public date: moment.Moment;
public disabled = false;
public showSpinners = true;
public showSeconds = false;
public touchUi = false;
public enableMeridian = false;
public minDate: moment.Moment;
public maxDate: moment.Moment;
public stepHour = 1;
public stepMinute = 1;
public stepSecond = 1;
public color: ThemePalette = 'primary';
public stepHours = [1, 2, 3, 4, 5];
public stepMinutes = [1, 5, 10, 15, 20, 25];
public stepSeconds = [1, 5, 10, 15, 20, 25];
}
似乎错误与我们使用的选择器有关。
有什么原因或缺少依赖项吗?
首先,您使用的是 ngx-mat-datetime-picker,它是 angular material 日期选择器的包装插件: https://www.npmjs.com/package/ngx-mat-datetime-picker
实现看起来不错,但一定会出现错误,因为您没有在属性中传递具有正确类型的预期值。您要传递给属性的某些组件 属性 未定义。 您可以重新访问演示实现并检查您是否发送了正确的值:
https://stackblitz.com/edit/demo-ngx-mat-datetime-picker?file=src%2Fapp%2Fapp.component.html
将@angular-material-components/datetime-picker 更新到版本 4.0.3 对我有用。 几个小时前发布了更新 https://www.npmjs.com/package/@angular-material-components/datetime-picker
在版本 4.0.3 中也适用于我。更新您的包裹。
我遇到了同样的问题 Angular11.1.0 Material11.1.0 日期时间选择器:5.0.3
我已经设法在一定程度上隔离了问题,它发生在这里:
_watchStateChanges() {
const datepickerStateChanged = this.datepicker ? this.datepicker.stateChanges : of();
const inputStateChanged = this.datepicker && this.datepicker.datepickerInput ?
this.datepicker.datepickerInput.stateChanges : of();
const datepickerToggled = this.datepicker ?
merge(this.datepicker.openedStream, this.datepicker.closedStream) :
of();
this._stateChanges.unsubscribe();
this._stateChanges = merge(this._intl.changes, datepickerStateChanged, inputStateChanged, datepickerToggled).subscribe(() => this._changeDetectorRef.markForCheck());
}
出于某种原因,此处未定义 datepickerStateChanged。这就是导致问题进一步发展的原因。还不知道为什么。如果有人有更多的答案,那就太棒了。现在,我要将此作为错误归档。
似乎已经在里面了: https://github.com/h2qutc/angular-material-components/issues/94
他们建议降级到 4.0.3,这是我明天要尝试的。
对于 angular v11 将 @angular-material-components/datetime-picker 升级到 v 5.1.0 修复了这个错误