Angular seed 在添加 router-outlet 后卡在 "Loading..."
Angular seed gets stuck at "Loading..." after adding router-outlet
在新的 Angular 种子应用程序 (ng new
) 中,一旦我将此添加到 app.component.html,应用程序就会卡在 "Loading...":
<router-outlet></router-outlet>
我试过注射 Router
:
export class AppComponent {
constructor(router: Router) { }
title = 'app works!';
}
事情变得更奇怪了。只要我有 router-outlet
标签,它就仍然停留在 "Loading..."。一旦我删除它(但 Router
仍在注入),我得到一个空白屏幕(即,甚至没有 "Loading...")。
app.module.ts 文件:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.ts:
import { Component } from '@angular/core';
import { Router } from '@angular/router';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
}
app.component.html:
<h1>
{{title}}
</h1>
<router-outlet></router-outlet>
更新
我收到四个浏览器错误:
好的,
import { RouterModule } from '@angular/router';
....
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule
],
您需要在 app.module.ts
文件中添加路由器模块
在新的 Angular 种子应用程序 (ng new
) 中,一旦我将此添加到 app.component.html,应用程序就会卡在 "Loading...":
<router-outlet></router-outlet>
我试过注射 Router
:
export class AppComponent {
constructor(router: Router) { }
title = 'app works!';
}
事情变得更奇怪了。只要我有 router-outlet
标签,它就仍然停留在 "Loading..."。一旦我删除它(但 Router
仍在注入),我得到一个空白屏幕(即,甚至没有 "Loading...")。
app.module.ts 文件:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.ts:
import { Component } from '@angular/core';
import { Router } from '@angular/router';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app works!';
}
app.component.html:
<h1>
{{title}}
</h1>
<router-outlet></router-outlet>
更新
我收到四个浏览器错误:
好的,
import { RouterModule } from '@angular/router';
....
imports: [
BrowserModule,
FormsModule,
HttpModule,
RouterModule
],
您需要在 app.module.ts
文件中添加路由器模块