ng new
在一个新的Angular 种子应用程序(
<router-outlet></router-outlet>
我确实尝试过注入Router
:
export class AppComponent {
constructor(router: Router) { }
title = 'app works!';
}
事情变得更奇怪了。只要我有router-outlet
标签,它仍然停留在“正在加载...”。一旦我删除它(但Router
仍在注入),我会得到一个空白屏幕(即,甚至不是“正在加载...”)。
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>
更新
我收到四个浏览器错误: