angular - 如何从Angular中的组件初始化包含其他接口的接口
问题描述
我正在使用返回 json 的服务调用 firebase,我在接口中对其进行了建模以便能够访问其数据,接口如下所示:
export interface Restaurante {
footer: Footer;
logo: string;
section_1: Section1;
section_2: Section2;
slide_header: Slide[];
}
export interface Footer {
contacto: Contacto;
logo_footer: string;
redes: Redes;
}
export interface Contacto {
direccion: string;
mail: string;
telefono: string;
}
export interface Redes {
facebook: string;
instagram: string;
}
export interface Section1 {
slide_promo: Slide[];
}
export interface Slide {
img: string;
}
export interface Section2 {
type_menu: TypeMenu[];
}
export interface TypeMenu {
menu: Menu[];
type: string;
}
export interface Menu {
description: string;
img: string;
price: string;
title: string;
}
我设法访问了完全初始化为联系人界面的界面,但是当我必须访问来自另一个界面内的页脚并又包含其他界面的数据时,就会出现问题。
datos: Contacto = {
direccion: 'string',
mail: 'string',
telefono: 'string',
};
constructor(private firebase: FirebaseService) {
this.firebase.datosHeader().subscribe(
(datos) => {
this.datos = datos.footer.contacto;
},
(err) => {}
);
console.log(this.datos);
}
当我按照以下方式执行此操作时,它会给我一个错误,所以我想知道如何访问页脚中的信息。
datos!: Footer;
/* datos: Contacto = {
direccion: 'string',
mail: 'string',
telefono: 'string',
}; */
constructor(private firebase: FirebaseService) {
this.firebase.datosHeader().subscribe(
(datos) => {
this.datos = datos.footer;
},
(err) => {}
);
console.log(this.datos);
}
解决方案
推荐阅读
- reactjs - Reactjs如何在非活动路由上切换类?
- c# - 尝试执行 SQL 更新时出错
- java - 解析 XML 文件跳过所有标签,除了一个带有 Java 的标签
- java-11 - 我可以将哪个 ojdbc 驱动程序用于 Oracle 12cR2 和 JDK 11 应用程序
- python - 当我在 GitHub 上上传笔记本时,HMTL 格式的 jupyter markdown 无法正确显示
- node.js - 在 mongoDB 中有条件地 findAndModify
- python - 如何避免python中动态分配的字符串中的转义字符?
- vba - MS 访问对话框
- c++ - 如何使用 STL 获取结构向量并将其转换为结构元素的向量
- javascript - 以最小值为条件的mongodb查询