gpt4 book ai didi

angular - 错误 : Cannot find primary outlet to load 'ProfileDetailsComponent'

转载 作者:太空狗 更新时间:2023-10-29 17:18:26 26 4
gpt4 key购买 nike

我正在尝试在我的应用程序中使用路由,使用路由器版本 3.0.0-beta.1,应用程序正在运行,但是当我单击 subjects.component.html 中的“下一步”按钮时,我期待获得“profileDetails.component.html”的内容。我创建了一个 plunkr,例如。这里:http://plnkr.co/edit/jR3jnC6CzmRVCoVFrn1W?p=preview它在 plunkr 上不起作用,但我猜是由于我正在使用的 Angular 2 Material 按钮等,但谁能告诉我哪里出错了?这是我的 main.ts:

import {bootstrap} from '@angular/platform-browser-dynamic';
import {enableProdMode} from '@angular/core';
import {AppComponent} from './app/app.component';
import {HTTP_PROVIDERS} from '@angular/http';
import { appRouterProviders } from './app/app.routes';

//import {disableDeprecatedForms, provideForms} from '@angular/forms';

bootstrap(AppComponent, [
// disableDeprecatedForms(),
// provideForms(),
HTTP_PROVIDERS,
appRouterProviders
]);

这是 app.routes.ts:

import { provideRouter, RouterConfig } from '@angular/router';
import {SubjectsComponent} from './subjects.component';
import {ProfileDetailsComponent} from './profileDetails.component';
import {AgreementComponent} from './agreement.component';

export const routes: RouterConfig = [
{ path: 'card', component: BasicCardComponent },
{ path: 'subjects', component: SubjectsComponent },
{ path: 'profile', component: ProfileDetailsComponent },
{ path: 'agreement', component: AgreementComponent }
];

export const appRouterProviders = [
provideRouter(routes)
];

这是我的 app.component.ts:

@Component({
selector: 'my-app',
template: `
<a [routerLink]="['/card']"></a>
<router-outlet></router-outlet>
` ,
// templateUrl: 'app/app.component.html',
styleUrls: ['app/app.component.css'],
directives: [BasicCardComponent, MdButton,MdCard,MdToolbar,MdIcon,MdInput,MD_INPUT_DIRECTIVES,MdCheckbox,ROUTER_DIRECTIVES],
providers:[MdIconRegistry]
})

流程有点像这样>profileDetails.component.html

最佳答案

在您的 app.component 中,您缺少路由器导出指令。

@Component({
selector: 'my-app',

// you can do somthing like this
template: `<card></card>
<router-outlet></router-outlet> `,
styles: ....
directives: [ROUTER_DIRECTIVES]
})
export class AppComponent {

}

plunker

关于angular - 错误 : Cannot find primary outlet to load 'ProfileDetailsComponent' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38408820/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com