简体   繁体   English

子组件无法访问 object 的属性

[英]Child component cannot access properties of object

I have a Quote model:我有一个报价 model:

export default class Quote {
    _id: string;
    quotee: string;
    body: string;
    dateQuoted: Date;
    dateCreated: Date;  
}

My parent component is:我的父组件是:

export class HomeComponent implements OnInit {

  quotes: Quote[] = []

  constructor(private quoteService: QuoteService) { }

  ngOnInit(): void {
    this.quoteService.getQuotes().subscribe((quote: Quote[]) => this.quotes = quote);
  }

}

I am sending the object in home.component.html我在 home.component.html 中发送 object

<div class="col-sm" *ngFor="let quote of quotes">
              <app-quote-box [quote]="quote"></app-quote-box>>
            </div>

My child component has an @Input() decoration:我的子组件有一个 @Input() 装饰:

export class QuoteBoxComponent implements OnInit {

  @Input() 
  quote: Quote;

  constructor() { }

  ngOnInit(): void {
  }

}

And I am trying to access the properties of the quote in the quote-box.component.html:我正在尝试访问quote-box.component.html中的报价属性:

<div class="quote-box">
  <h2>{{quote.quotee}} </h2>
  <p>"{{quote.body}}"</p>
</div>

I am getting the error:我收到错误消息:

Property 'quotee' does not exist on type 'Quote'. 'quote' 类型不存在属性 'quotee'。

Can someone explain to me what I am doing wrong?有人可以向我解释我做错了什么吗? Thank you for any help感谢您的任何帮助

Try to change to:尝试更改为:

import { Component, OnInit, Input } from '@angular/core'; 
import { Quote } from '@angular/compiler'; 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM