angular - 无法将子组件显示到父组件中
问题描述
我有一个父组件ViewCalendars
视图-calendars.component.html
<div class="container-calendar">
<ca-month-header>
</ca-month-header>
</div>
查看日历.component.ts
import { Component, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { MonthHeaderComponent } from './ca-month-header/month-header.component';
@Component({
selector: 'ca-view-calendars',
templateUrl: './view-calendars.component.html',
styleUrls: ['./view-calendars.component.css']
})
export class ViewCalendarsComponent implements OnInit {
@ViewChild(MonthHeaderComponent) header: any;
ngOnInit() {
}
}
和一个子组件MonthHeader
月-header.component.html
<div class="month-header">
<div class="month">
<label> Month </label>
</div>
</div>
月头.component.ts
import { Component, OnInit, Input } from '@angular/core';
@Component({
selector: 'ca-month-header',
templateUrl: './month-header.component.html',
styleUrls: ['./month-header.component.css']
})
export class MonthHeaderComponent implements OnInit {
constructor() { }
ngOnInit() {
}
}
这就是我在 DevTools 中得到的。
我已经在模块中导入了组件,我不明白为什么不显示子组件
我错过了什么?
解决方案
Angular 编译器控制台上是否有任何错误?
如果没有,我建议您尝试在 Month 标头组件中打印不同的内容,例如h2
标签中的内容,然后查看是否打印。您还应该确认您的组件是否在模块中正确声明和导入。
推荐阅读
- python - 无法使用 BeautifulSoup 抓取特定表
- python - 如何使用生成器或其他方式设置 TF 2.4 训练数据
- rest - express nodejs Passportjs 总是失败Rederict
- pandas - 比较两个不同的数据框并更改列值
- python-3.x - 使用 python3 的 tkinter 弃用警告
- flutter - 获取参数上的flutter Http问题
- python - 将第一列值与 Pandas 中的列标题连接起来,得到一个又高又瘦的格式表
- android - 类 User 没有定义无参数构造函数。如果您使用 ProGuard,请确保这些构造函数没有被剥离
- javascript - Webpack:HMR 更新检查失败错误:Manifest Request to ..... 在 XMLHttpRequest 处超时
- javascript - 菜单按钮有问题,切换功能不起作用