【问题标题】:Angular 7 - Can't bind to @Input() propertyAngular 7 - 无法绑定到 @Input() 属性
【发布时间】:2019-01-22 18:10:17
【问题描述】:

使用 Angular 7.2.0,我有以下组件:

import { Component, OnInit, Input } from '@angular/core';
import { Customer} from "../../services/customers.model";

@Component({
  selector: 'app-summary',
  templateUrl: './summary.component.html',
  styleUrls: ['./summary.component.css']
})

export class SummaryComponent {
  @Input() customer: Customer;
}

在父模板中,我有:

 <div class="mdl-cell mdl-cell--3-col" *ngFor="let c of customers">
   <summary [customer]="c"></summary>
</div>

尝试编译它会引发以下异常:

ERROR in : Can't bind to 'customer' since it isn't a known property 
  of'summary'. ("
  <div class="mdl-cell mdl-cell--3-col" *ngFor="let c of customers">
    <summary [ERROR ->][customer]="c"></summary>
  </div>
")

我无法弄清楚这里可能会发生什么,因为提到的属性是在组件中定义的。有人可以帮忙吗?

谢谢, 尼古拉斯

【问题讨论】:

  • 应该是&lt;app-summary .... 而不是&lt;summary ...
  • 就是这样,非常感谢

标签: angular binding


【解决方案1】:

您的选择器是:'app-summary'

使用&lt;app-summary [customer]="c"&gt;&lt;/app-summary&gt;

【讨论】:

    【解决方案2】:

    你应该绑定&lt;app-summary [customer]=""&gt;,同样,你绑定到&lt;summary&gt;,这是一个HTML标签,而不是一个角度组件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-11-29
      • 2018-09-29
      • 2017-11-29
      • 1970-01-01
      • 2019-04-08
      • 2019-11-01
      • 1970-01-01
      相关资源
      最近更新 更多