You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.17 11:20:30