【发布时间】:2018-03-27 01:22:05
【问题描述】:
我是 Angular 2 的初学者,并从一个包含以下文件的小项目开始:
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { MaterialModule } from './material/material.module';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
MaterialModule,
BrowserAnimationsModule,
AppComponent,
NgModule
],
bootstrap: [AppComponent]
})
export class AppModule {
}
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
title = 'App Title';
}
app.component.html
<span>Welcome to {{title}}</span>
另外,我的 index.html 看起来像这样:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>My App</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
我遇到的问题是,即使一切编译正常,<app-root> 标记在结果页面中仍然为空,并且我的模板 HTML 没有被添加。我已经通过更改模板 URL 测试了是否是模板加载的问题,但它无法找到我的模板文件并且编译失败。这意味着这不是问题。
这里有什么我遗漏的吗?
【问题讨论】:
标签: angular typescript angular-components