javascript - Angular TypeScript:无法将数组分配给新数组
问题描述
所以在这个组件中,我从 api“adherents”中获取了一个对象数组,它工作正常,我用来显示一个表,但是当我创建一个新数组“temp_adherents”,并将第一个数组分配给它并尝试使用它,它是空的,在控制台中,我收到一个新数组未定义的错误,这是我的代码:
export class AdherentsComponent implements OnInit {
adherents: adherent[];
constructor(private adherentService: AdherentService, private alertify: AlertifyService) { }
ngOnInit() {
this.getAdherents();
}
temp_adherents = this.adherents // this is where the problem is
getAdherents() {
this.adherentService.getAdherents().subscribe((
adherents: adherent[]) => {
this.adherents = adherents;
}, error => { this.alertify.error(error); })
}
}
解决方案
推荐阅读
- c - 为什么下面的 printf 会导致分段错误?
- ttl - 如何在 Rocks DB 上正确设置 TTL?
- mysql - MYSQL 如何在 MYSQL 中执行两个日期之间的自定义月差?
- reactjs - 使用“react-pdf”时反应应用程序抛出错误
- swift - iOS UINavigationBar - 当大标题文本切换到标题文本时
- amazon-web-services - 在 AWS Glue 中解析动态数据帧的架构
- php - Laravel 5.7,在用户注销之前做一些事情
- python - 对 Pandas 时间戳列进行分箱
- c++ - C++,获取windows目录下最后修改的文件
- c# - 如何根据datagridview外部的组合框过滤datagridview组合框中的结果