我有一个由两列组成的页面。一个包含垂直步进器,另一个包含每个步骤的说明。我想根据当前步骤来更新此描述,因此请收听selectionChange-Event。问题是,当我查找selectedIndex时,得到的是先前选择的步骤,而不是我现在所在的步骤。
HTML:
<div class="row">
<div class="col-7 stepperColumn">
<mat-vertical-stepper (selectionChange)="onStepChange(eventCreationStepper)" #eventCreationStepper>
<!--some steps-->
</mat-vertical-stepper>
</div>
<div class="col-5">
<!--some descriptions-->
</div>
</div>
JS:
public onStepChange(stepper: MatStepper) {
console.log(stepper.selectedIndex);
}
到目前为止,我之前构建无限滚动器的所有尝试都失败了。我目前正在处理的组件使用 Angular 的虚拟滚动,并且应该在达到虚拟滚动视口的某个索引时更新数据源。虽然 BehaviorSubject 确实得到了更新,但我在视图中看不到新版本。
我的组件如下所示:
import {Day, Month, Selected, Weekday} from './datepicker';
import {CdkVirtualScrollViewport} from '@angular/cdk/scrolling';
import {BehaviorSubject} from 'rxjs';
@Component({
selector: 'app-calendar-datepicker',
templateUrl: './calendar-datepicker.component.html',
styleUrls: ['./calendar-datepicker.component.scss']
})
export class CalendarDatepickerComponent implements OnInit {
months: BehaviorSubject<any[]> = new BehaviorSubject<any[]>([]);
previousScrollIndex: number;
@ViewChild('dateScroller') dateScroller: CdkVirtualScrollViewport;
constructor() {
}
ngOnInit() {
/*initialization of the array*/
const initialMonths = [];
const month = new Month(this.currentDate);
const date = moment(this.currentDate);
const nextMonth = new Month(date.add(1, 'M'));
const nextDate = moment(date);
const monthAfterNextMonth = …Run Code Online (Sandbox Code Playgroud)