【发布时间】:2019-01-03 07:09:04
【问题描述】:
我有一个显示来自外部 API 的数据的数据表,我希望将表页面上的项目/元素的数量保存在本地存储中
这是我迄今为止尝试过的:
ngOnInit() {
this.moviesService.getPopularTVShows().subscribe(res => {
this.dataSource = new MatTableDataSource(res.results);
this.dataSource.paginator = this.paginator;
this.dataSource.sort = this.sort;
localStorage.setItem(this.dataSource, this.dataSource.length);
console.log(localStorage.length);
});
}
当我运行我的应用程序时,控制台显示undefined
我的代码有什么问题?欢迎任何帮助或建议,新手尝试新事物。
【问题讨论】:
-
看这个链接(LocalStorage和SessionStorage的完整解释):stackoverflow.com/questions/40589730/local-storage-in-angular-2/…
-
你应该显示 localStorage 变量的来源。
标签: angular html typescript local-storage