即使在 angular 2 项目中成功输出后,我也会收到错误消息。为什么这样?
I am getting error even after successful output in angular 2 project. Why So?
我在 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(在app-demo-demo-list.html)
<div>This is demo list page</div>
路由器出口永远不会呈现,因为您没有从任何地方引用 app.component.html。我相信你不应该使用
templateUrl: './demo/demo-list.html'
但是
templateUrl: './app.component.html'
我在 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(在app-demo-demo-list.html)
<div>This is demo list page</div>
路由器出口永远不会呈现,因为您没有从任何地方引用 app.component.html。我相信你不应该使用
templateUrl: './demo/demo-list.html'
但是
templateUrl: './app.component.html'