我有一个具有不同模式的组件,在每个模式中,我必须显示每个属性的信息,这些信息在另一个组件中。我有一个对象向量中的信息。根据我所读到的,我必须在组件(父组件和子组件)之间使用绑定。我的疑问是,我必须将一个对象传递给另一个组件,然后显示它们的数据,我该怎么做呢?我必须声明一个对象类型real @input,如何将整个对象从一个组件绑定到另一个组件?我想做的是在该组件的模板中显示该对象的值。
以下是我所拥有的示例:
我有一个类,它就是我所说的对象:
export class Inmueble {
nombre: string="";
id: string="";
baño: number=0;
estacionamiento: number=0;
metro: number=0;
precio: number=0;
fotos: string[]=[];
}
我将该类导入到COMPONENT1中,在那里我通过对API的请求用数据填充它。我想要的是(填充该对象之后)将其传递给COMPONENT2,我的想法是在COMPONENT2中这样做:
import { Component, OnInit, Input } from '@angular/core';
import { Inmueble } from '../modelos/inmueble';
class {
@Input vector: inmueble[];
}
但是如何处理从COMPONENT1填充到COMPONENT2的对象呢?在示例中,我看到他们对单个变量这样做: variable = "value",但这将是一个向量,我认为逐行执行并不重要。我想要实现的是在COMPONENT2模板中显示该对象。在此之前,感谢大家。致以问候!
编辑:
组件1:
import { Component, OnInit, Input} from '@angular/core';
import { Inmueble } from '../modelos/inmueble';
@Component({
selector: 'app-modal',
templateUrl: `<p>Model: {{prueba.nombre}} </p>`,
styleUrls: ['./modal.component.css']
})
export class ModalComponent implements OnInit, Input {
@Input() prueba: Inmueble;
constructor() { }
ngOnInit() {
}
}
组件2:
<app-modal [prueba]="inmuebles[0]" > </app-modal>
我分配房地产,因为在这个组件中我有一个属性数组,所以在理论上我会将一个属性分配给一个属性。
向我显示了这个错误:
ERROR in ./src/app/modal/modal.component.ts
Module not found: Error: Can't resolve './<p>Model: {{prueba.nombre}} </p>' in '/home/julian/Seaconfiable/src/app/modal'
https://stackoverflow.com/questions/56568382
复制相似问题