You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular 10.1.0分页开发遇TS2339错误:WritableSignal无slice属性

解决Angular中WritableSignal<Data[]>无slice方法的错误

错误原因

你直接对WritableSignal对象调用slice方法,但WritableSignal本身是响应式包装器,并非数组。要访问它内部的数组数据,必须调用signal函数(即this.data())来获取实际的数组值。

修正后的代码

组件中修正paginatedData getter

get paginatedData() {
  const start = (this.currentPage - 1) * 100;
  const end = start + 100;
  // 先获取signal内部的数组,再执行slice操作
  return this.data().slice(start, end);
}

关于你之前的尝试

你写的const dataArray = Array.from(this.data().values)存在两个问题:

  1. 数组的values()方法需要加括号调用:this.data().values()
  2. 完全没必要用Array.from,因为this.data()直接返回数组,直接使用即可:
    const dataArray = this.data();
    

额外注意

Angular 10.1.0本身并不内置Signals功能(Signals是Angular 16及以上版本才引入的),如果你是在Angular 10中使用Signals,可能依赖了第三方库或者版本配置有误,需要确认这一点避免后续其他问题。

内容的提问来源于stack exchange,提问作者shdp

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 13:53:15