[英]Angular how to make a selector recognized by a second component?
I have xxx.component file contains this code:我有 xxx.component 文件包含以下代码:
@Component({
selector: 'app-two',
template: '<p>hello</p>',
})
export class MyTwoComponent {
constructor() {}
}
@Component({
selector: 'app-my',
template: '<app-two></app-two>', ->>>>Does not recognize this selector
})
export class MyPanelComponent extends MyTwoComponent {
constructor() {
super();
}
}
The problem is that creates and error saying that it does not recognize the selector.问题是创建和错误说它不识别选择器。 I tried to use NgModule but gets worse.我尝试使用 NgModule 但变得更糟。 Any suggestions?有什么建议么? Thank you.谢谢你。
UPDATE ONE I found the solution!更新一我找到了解决方案! But it needs to change standalone.但它需要独立更改。 And i can't do that in my case...在我的情况下,我不能这样做......
@Component({
selector: 'app-two',
standalone: true,
template: '<p>hello</p>',
})
export class MyTwoComponent {
constructor() {}
}
@Component({
imports: [MyTwoComponent],
selector: 'app-my',
standalone: true,
template: '<app-two></app-two>',
})
export class MyPanelComponent extends MyTwoComponent {
constructor() {
super();
}
}
Declare the component in the same module the original component is in.在原始组件所在的同一模块中声明组件。
Read more on modules https://angular.io/guide/architecture-modules#introduction-to-modules阅读更多关于模块https://angular.io/guide/architecture-modules#introduction-to-modules
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.