即使在角度2项目中成功输出后,我也会收到错误。为什么这样?

问题描述 投票:0回答:1

我在visual studio 2017中创建了一个角度(版本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>
angular angular2-template
1个回答
1
投票

由于您没有从任何地方引用app.component.html,因此永远不会呈现路由器插座。我相信你不应该使用

templateUrl: './demo/demo-list.html'

templateUrl: './app.component.html'
© www.soinside.com 2019 - 2024. All rights reserved.