【问题标题】:Basic Angular Components not Displaying in Browser [duplicate]基本 Angular 组件未显示在浏览器中 [重复]
【发布时间】:2019-08-20 05:19:16
【问题描述】:

我刚刚运行ng serve -o,只看到我的index.html 文件显示在我刚开始修改的角度应用程序中。该页面现在只是打招呼:

// index.html
<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Appclient</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>hello</app-root>
</body>
</html>

app.component.html 有这个:

world
<app-header></app-header>
<router-outlet></router-outlet>

app.component.ts 如下:

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

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = 'startlistsclient';
}

我不确定我错过了什么。

控制台错误是:

ReferenceError: global is not defined

index.js:43 网络包 18 ​

【问题讨论】:

标签: javascript angular angular8


【解决方案1】:

你需要在app.module.ts中使用@angular/route

app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { RouterModule, Routes } from '@angular/router';

import { AppComponent } from './app.component';
import { HelloComponent } from './hello.component';

const routes: Routes = [
  { path: 'hello', component: HelloComponent }
];

@NgModule({
  imports:      [ BrowserModule, FormsModule, RouterModule.forRoot(routes) ],
  exports:      [ RouterModule ],
  declarations: [ AppComponent, HelloComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

&lt;app-header&gt;&lt;/app-header&gt; 这应该被定义。

查看working demo

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-12-15
    • 2018-08-19
    • 1970-01-01
    • 2020-06-18
    • 2010-09-07
    • 2014-12-07
    • 2018-12-02
    相关资源
    最近更新 更多