我是 angular-gridster2 的新手,但我设法对我的 gridster 的布局进行了一些动态更改,所以我会尽力帮助你。
我看不到你的“选项”属性来自哪里,但它应该是GridsterConfig的一个实例,所以你的 .ts 文件的开头应该是这样的:
import { GridsterConfig, GridsterItem } from 'angular-gridster2';
options: GridsterConfig;
定义选项后,您可以通过调用 api 的optionsChanged方法来刷新 gridster 的布局,如下所示:
test(){
this.myAptInfolet.cols = 2;
this.options.api.optionsChanged();
}
您可以参考angular-gridster2 github找到一个关于如何与项目进行动态交互并更改网格布局的非常小而干净的示例:
import { GridsterConfig, GridsterItem } from 'angular-gridster2';
options: GridsterConfig;
dashboard: Array<GridsterItem>;
static itemChange(item, itemComponent) {
console.info('itemChanged', item, itemComponent);
}
static itemResize(item, itemComponent) {
console.info('itemResized', item, itemComponent);
}
ngOnInit() {
this.options = {
itemChangeCallback: AppComponent.itemChange,
itemResizeCallback: AppComponent.itemResize,
};
this.dashboard = [
{cols: 2, rows: 1, y: 0, x: 0},
{cols: 2, rows: 2, y: 0, x: 2}
];
}
changedOptions() {
this.options.api.optionsChanged();
}
removeItem(item) {
this.dashboard.splice(this.dashboard.indexOf(item), 1);
}
addItem() {
this.dashboard.push({});
}
我希望这会有所帮助。