我已经在Visual Studio 2017中创建了angular(2.1.0版)项目。 一切正常,只是出现以下错误:
EXCEPTION: Uncaught (in promise): Error: Cannot find primary outlet to load 'AppComponent'
Error: Cannot find primary outlet to load 'AppComponent'
控制台中出现了总共5个错误,但运行时代码中没有这些错误。
app.routes.ts
import { ModuleWithProviders } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
//import { AboutComponent } from './demo/about.component';
const appRoutes: Routes = [
{
path: 'Home',
children: [
{
path: 'Index',
component: AppComponent
},
//{
// path: 'About',
// component: AboutComponent
//}
]
},
{ path: '**', component: AppComponent }
];
export const routing: ModuleWithProviders = RouterModule.forRoot(appRoutes);
app.component.ts
import { Component, OnInit, ViewContainerRef } from '@angular/core';
// Add the RxJS Observable operators we need in this app.
import './js/ng/rxjs-operators';
@Component({
moduleId: module.id,
selector: 'demo-tag',
templateUrl: './demo/demo-list.html'
})
export class AppComponent {
constructor(private viewContainerRef: ViewContainerRef) {
this.viewContainerRef = viewContainerRef;
}
name = 'First Angular 2 Application';
}
app.component.html
<router-outlet></router-outlet>
demo-list.html (在应用程序中-演示-demo-list.html)
<div>This is demo list page</div>
答案 0 :(得分:1)
路由器插座永远不会渲染,因为您没有从任何地方引用app.component.html。我相信您不应该使用
templateUrl: './demo/demo-list.html'
但是
templateUrl: './app.component.html'