【发布时间】:2020-08-17 12:07:35
【问题描述】:
我是角度的新手。我遇到了有关组件的问题。我创建了一个名为 test 的组件。
当我运行代码时,我得到了正确的输出,但是当我从 app.component.html 中删除标签时,我得到了空白网页作为输出。
这里是test.component.ts的代码
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-test',
templateUrl: './test.component.html',
styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}
这里是test.component.html的代码
测试正常
这里是app.component.html的代码
<app-test></app-test>
请纠正我哪里做错了。是否有必要在 app.component.html 中声明每个组件的每个选择器标记(根 html 代码)
【问题讨论】:
-
这个问题实在看不懂,看了好几遍
-
如果您不在模板中使用您的组件(或通过 componentFactory 动态添加它),则不会使用它。那是预期的行为。如果您还没有,我强烈建议您阅读 Angular Tour of Heroes 教程,它涵盖了构建 Angular 应用程序的基础知识。 angular.io/tutorial
标签: angular typescript