类型'[]'中缺少Angular7'length'

问题描述 投票:-1回答:1

我正在使用简单的值来提取一些数据,并在页脚中显示并获取此信息。

src / app / layout / customer / customerform / customerform.component.ts(25,7)中的错误:错误TS2322:类型“页脚”不能指定为“页脚[]”类型。 “页脚”类型中缺少属性“长度”。

Component.ts

  footers: Footer[];

  ngOnInit() {
    this.getFooter();
    console.log(this.footers);
  }

  getFooter() {
    this.bone.getFooter().subscribe( actions => {
      this.footers = actions.payload.data() as Footer;
    });
  }

model.ts

export interface Footer {
  id?: string;
  color?: string;
  bg?: string;
  text?: string;
}

service.ts

 getFooter() {
    return this.footerCollection.doc("style").snapshotChanges();
  }
angular google-cloud-firestore angularfire2
1个回答
2
投票

你需要改变从FooterFooter[]的施法:

this.footers = actions.payload.data() as Footer[];

您需要初始化footers以不获取undefined错误:

footers: Footer[] = [];
© www.soinside.com 2019 - 2024. All rights reserved.