我正在尝试使用input
attr将数据从一个组件发送到另一个组件。
但是我收到了这个错误
VM575 zone.js@0.6.17?main=browser:484 Unhandled Promise rejection: Template parse errors:
Can't bind to 't' since it isn't a known property of 'row-item'.
1. If 'row-item' is an Angular component and it has 't' input, then verify that it is part of this module.
2. If 'row-item' is a Web Component then add "CUSTOM_ELEMENTS_SCHEMA" to the '@NgModule.schema' of this component to suppress this message.
(" <ul>
<li *ngFor="let tt of todoService.todos">
<row-item [ERROR ->][t]='tt'></row-item>
</li>
我在演示中添加了这个
import {Component, Input} from "@angular/core";
@Component({
selector:'row-item',
template :`<div>
<span>{{t}}</span>
</div>`
})
export class TodoRow{
@Input t;
}
像这样使用
@Component({
selector: 'todo-list',
template: `<div>
<ul>
<li *ngFor="let tt of todoService.todos">
<row-item [t]='tt'></row-item>
</li>
</ul>
</div>`
})
答案 0 :(得分:2)
您的声明应该是这样的:
@Input() t;
答案 1 :(得分:1)
在为组件定义输入时忘了添加()。
import {Input} from '@angular/core';
Input() t;
您应该在为组件提供输入时尝试提供基本名称:
@Input('t') t;
希望这有帮助。