ParentComponent.html
<div ["child-component"]> </div>ChildComponent.html
<div> This is a Child Component </div>ChildComponent.ts
import { Component } from '@angular/core';
import { FormBuilder } from '@angular/forms';
@Component({
selector: 'child-component',
templateUrl: './child.component.html',
styleUrls: ['./child.component.css']
})
export class ChildComponent{
constructor(private formBuilder: FormBuilder) {}
}问题:加载ParentComponent时不渲染子组件。
错误:控制台中没有错误,调试点在子组件中未命中。
我尝试在ParentComponentMoudle.ts文件中包含ChildComponentModule。
注意:我正在从Angular 4迁移到Angular 8。
摘要:我想要做的就是在页面上加载一个非常基本的自定义组件
发布于 2019-08-12 23:30:49
如果每个组件都有单独的模块,则在父模块中添加子模块引用,并在父模块中导入子组件。然后在父级模块中添加父模块引用,并导入父组件。然后,在GrandParent.html中
<ParentComponent> </ParentComponent>添加类似上面的内容
发布于 2019-08-15 23:56:00
在父组件的视图(html)中,使用子组件的选择器,而不是类名:
<child-component></child-component>https://stackoverflow.com/questions/57463711
复制相似问题