首页 > 解决方案 > Angular 9新项目-ng服务时未加载应用程序根

问题描述

我升级到 Angular 9 并在创建新项目后:ng new test - 当我在做时:ng serve - 页面未加载 app-root。当我在 index.html 中添加一些文本时 - 它显示文本但不显示 app-root。我降级到 Angular 8 和同样的问题。我在控制台中没有错误。我做了 ng build --prod 并且没有错误。

<!-- index.html -->
<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8">
    <title>Test1</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>
<p>test</p>
    <app-root></app-root>
</body>

</html>

app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule
  ],
  providers: [],
  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 = 'test1';
}

app.component.html


<p>Test inside app.component.html</p>

标签: angularangular-cli

解决方案


推荐阅读