我正在尝试使用 *ngFor
渲染组件列表:
<componentx
*ngFor="let a of data"
[viewName]="a.name"
[viewQuery]="a.prop2"
[viewValues]="a.prop3"></componentx>
// ...
export class App {
public data:any[];
constructor() { this.data = [{name: 'foo', prop2: 'bar', prop3: 'hello'}]}
}
这是组件本身:
export class ComponentX {
@Input() viewName:string;
@Input() viewQuery:string;
@Input() viewValues:any[];
}
当我运行此代码时,出现以下错误:
Error: Uncaught (in promise): Template parse errors:
Can't bind to 'viewName' since it isn't a known native property ("
<componentx
*ngFor="let a of data"
[ERROR ->][viewName]="a.name"
[viewQuery]="a.prop2"
[viewValues]="a.prop3"></componentx>
我做错了什么?
最佳答案
此错误通常意味着:
1-特定的 @Input 不存在于您的组件中,但在您的情况下它存在。
2-您忘记在根应用程序模块中声明您的组件。
import {ComponentX} from 'its/path';
@NgModule({
declarations:[ComponentX]
})
export class AppModule {
}
关于javascript - 无法绑定(bind)到 ___,因为它不是已知的 native 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41389200/