- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用新的 Angular 7 Material CDK 拖放功能将项目从一个列表移动到另一个列表,并且在移动这些项目时视觉上一切都在晃动,但是当通过列表更改项目时,我收到一条错误消息,说无法获取属性(列表数组)来自未定义,即使我使用的是“item?.array”的东西
在构造函数中:
this.userService.getUserById('some-user-id').subscribe(user => {
this.user1 = user;
console.log(user1.route.routePoints); // I see the array in log
});
this.userService.getUserById('some-other-user-id').subscribe(user => {
this.user2 = user;
console.log(user2.route.routePoints); // I see the array in log
});
<div cdkDropList #routeA="cdkDropList" cdkDropListOrientation="horizontal"
[cdkDropListData]="user1?.route?.routePoints"
class="list" (cdkDropListDropped)="drop($event, false, user1)"
[cdkDropListConnectedTo]="[queue, routeB]">
drop(event: CdkDragDrop<RoutePoint[]>, fromQueue: boolean = false, user: User) {
if (event.previousContainer === event.container) {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
} else {
transferArrayItem(event.previousContainer.data, event.container.data, event.previousIndex, event.currentIndex);
}
this.userService.updateUser(user);
}
最佳答案
作为 marcinolawski @ https://github.com/angular/components/issues/15948提到,原因是:
The problem is that _DragRef.initialContainer == undefined. This is because _DragRef.initializeDragSequence() is called earlier than _DragRef.withDropContainer(). _initializeDragSequence() initializes the _initialContainer based on _dropContainer, _dropContainer is initialized by _withDropContainer() but because _initializeDragSequence() is called earlier than _withDropContainer() _initialContainer is set to undefined. More info: https://github.com/angular/components/blob/master/src/cdk/drag-drop/drag-ref.ts
ngAfterViewChecked() {
this.cdRef.detectChanges();
}
当然还有将 ChangeDetectorRef 注入(inject)到组件中:
constructor(
private cdRef: ChangeDetectorRef
}
关于angular - 无法读取未定义的属性 - cdkDropListData 拖放 Angular Material,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53878892/
我正在使用新的 Angular 7 Material CDK 拖放功能将项目从一个列表移动到另一个列表,并且在移动这些项目时视觉上一切都在晃动,但是当通过列表更改项目时,我收到一条错误消息,说无法获取
我是一名优秀的程序员,十分优秀!