父子组件调用
约 80 字小于 1 分钟
2026-09-16
在一个组件中使用另外一个组件,需要使用 ts 先导入, 然后在 @Component 中的 imports 中注册, 最后在 html 中使用。
import { Component, signal } from '@angular/core'
import { ChildComponent } from './child.ts'
@Component({
selector: 'app-root',
styleUrl: './app.css',
template: `
<child-component />
`,
imports: [ChildComponent],
})
export class App {
inputText = signal('')
}