は正気を失うことなく作業をルーティングゲットゴールのためにすべてのパラメータを解決できません。
エラー
Error: Can't resolve all parameters for Router: (?, ?, ?, ?, ?, ?, ?, ?)
app.routing.ts
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { NavbarComponent } from './navbar/navbar.component';
import { CustomerComponent } from './customer/customer.component';
export const appRoutes: Routes = [
{ path: '', redirectTo: 'customers', pathMatch: 'full' },
{ path: 'customers', component: CustomerComponent },
];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
app.module.ts
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { routing } from './app.routing';
import { AppComponent } from './app.component';
import { NavbarComponent } from './navbar/navbar.component';
import { CustomerComponent } from './customer/customer.component';
@NgModule({
imports: [
BrowserModule,
FormsModule,
routing
],
declarations: [
AppComponent,
NavbarComponent,
CustomerComponent,
],
providers: [
// ...
],
bootstrap: [ AppComponent ]
})
export class AppModule {
// ...
}
app.component.ts
import { RouterLink } from '@angular/router';
import { HTTP_PROVIDERS } from '@angular/http';
import { Component } from '@angular/core';
import { NavbarComponent } from './navbar/navbar.component';
import { CustomerComponent } from './customer/customer.component';
export { Config } from './config/env.config';
@Component({
moduleId: module.id,
selector: 'app',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css'],
directives: [NavbarComponent, CustomerComponent],
providers: [HTTP_PROVIDERS, RouterLink]
})
export class AppComponent
{
constructor() {
// console.log('Environment config', Config);
}
ngOnInit() {
// ...
}
}
navbar.component.ts
import { Router, ROUTER_DIRECTIVES } from '@angular/router';
import { Component } from '@angular/core';
@Component({
moduleId: module.id,
selector: 'navbar',
templateUrl: 'navbar.component.html',
styleUrls: ['navbar.component.css'],
directives: [ROUTER_DIRECTIVES],
providers: [Router],
})
export class NavbarComponent
{
version: string;
versionIsVisible: boolean;
constructor() {
this.version = '<%= VERSION %>';
}
ngOnInit() {
// ...
}
}
app.component.html
<navbar></navbar>
<router-outlet></router-outlet>
navbar.component。 HTML
<a routerLink="/customers">Customers</a>
「app.component.html」に ' router-outlet>'がありますか? –
はい、あります。 (私はそれを含むように投稿を更新しました) – Donnie