我有一个简单的应用角度与一个组成部分。这是教程中的todo应用程序。我想添加第二个组件。我的文件夹应用程序,我现在有文件夹新组件1。在这个文件夹中,我有四个文件:
在新组件中,我有:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-new-component1',
templateUrl: './new-component1.component.html',
styleUrls: ['./new-component1.component.css']
})
export class NewComponent1Component implements OnInit {
constructor() { }
ngOnInit() {
}
}
在新的-Component1.Component.html文件中,我只想显示一个带有样例文本的段落。我的app.module.ts看起来是这样的:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
import { NewComponent1Component } from './new-component1/new-component1.component';
@NgModule({
declarations: [
AppComponent,
NewComponent1Component
],
imports: [
BrowserModule,
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
NewComponent1Component被添加到声明中。每个人的思想都是没有错误的。但是,当我想在index.html中显示来自组件的数据时:
<body>
<app-root></app-root>
<app-new-component1></app-new-component1>
</body>
什么都不显示。只显示应用程序根目录的内容。这是使用todo-app生成的第一个组件。如何显示来自组件的数据?
发布于 2019-05-21 09:35:56
例如,它不应该将app-new-component1
标记放在index.html
文件中,而应该放在app.component.html
文件中。你实际上是把角度分量放在角度应用程序之外。
https://stackoverflow.com/questions/56243383
复制相似问题