html - 为什么我的 Angular 应用程序显示我的 html 文件的路径而不是它的内容?

标签 html angular typescript

我从 Angular 开始。我正在创建一个非常简单的应用程序,它使用两个组件。一个默认应用程序组件和一个在应用程序组件的 html 文件中使用的第二个组件。

但是,在运行该应用程序时(有关相关文件,请参阅下面的文件),我得到以下输出:

App component

./server.component.html

在我的例子中,而不是 html 文件中的实际内容:

App component

The server component

谁知道我做错了什么?

这是我的模块: (app.module.ts)

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { ServerComponent } from './server/server.component';

@NgModule({
  declarations: [
    AppComponent,
    ServerComponent
  ],
  imports: [
    BrowserModule, 
    FormsModule,
    HttpModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

我的主要组件的 html 文件 (app.component.html)

<p>App Coponent</p>
<hr>
<app-server></app-server>

服务器组件 (server/server.component.ts)

import { Component } from '@angular/core';

@Component({
    selector: 'app-server',
    template: './server.component.html'
})
export class ServerComponent {

}

最后,服务器组件的 html 文件 (server/server.component.html)

<p>The server component</p>

最佳答案

改变

@Component({
    selector: 'app-server',
    template: './server.component.html'
})

@Component({
    selector: 'app-server',
    templateUrl: './server.component.html'
})

关于html - 为什么我的 Angular 应用程序显示我的 html 文件的路径而不是它的内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55872045/

相关文章:

javascript - 如何在 AngularJs2 中添加动态 formControlName

html - 样式问题 - CSS 忽略空白 : nowrap;

javascript - 错误 : Type String is not assignable to type '{ name : string; }' in Angular

php - 使用 jQuery 滑动一个 div 打开一个关闭

angular - 如何在 Angular 7 中为 formControl 设置动态值

angular - 从 Angular 2 中的子组件更新父组件属性

jquery-ui - 将 Aurelia 与 Webpack 结合使用时找不到模块 'jquery-ui'

typescript - 在声明文件中将 namespace 从外部模块重新导出到全局

html - 在响应式屏幕上隐藏 div

javascript - 如何在不将所有其他元素 z-index 变为负数的情况下使用 z-index 时使链接可点击?