Angular 17 独立组件属性选择器无法生效问题求助
Angular 17 独立组件属性选择器无法生效问题求助
我最近在学Angular 17的独立组件,结果卡在属性选择器的使用上了。按照官方文档的说明,组件应该支持属性选择器,但实际用的时候总是报错。
当我尝试用属性选择器调用组件时,会弹出这个错误:
Can't bind to 'app-list-item' since it isn't a known property of 'tr'.
我特意试了类型选择器和类选择器,这两种都能正常工作,偏偏属性选择器就不行。
下面是我的组件代码示例:
list-item-component.ts
import { Component } from '@angular/core'; @Component({ selector: '[app-list-item]', // 属性选择器的定义方式 standalone: true, templateUrl: './list-item.component.html', styleUrls: ['./list-item.component.css'] }) export class ListItemComponent { // 组件逻辑代码 }
我在父组件里是这么使用的:<tr app-list-item></tr>,结果就触发了上面的错误。
备注:内容来源于stack exchange,提问作者Mathieu
相关产品推荐
相关产品推荐

