【发布时间】:2016-11-19 09:56:30
【问题描述】:
我正在尝试在我的应用程序中使用路由,使用路由器版本 3.0.0-beta.1,应用程序正在运行,但是当我单击 subject.component.html 中的“下一步”按钮时,我期待获得“profileDetails.component.html”的内容。我创建了一个 plunkr 例如。在这里:@ 987654321@ 虽然我猜由于我正在使用的角度2材料按钮等原因,它在plunkr上不起作用,但是谁能告诉我我哪里出错了? 这是我的 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]
})
流程有点像这个 app.component.ts->basicCard.component.ts->basicCard.component.html->subjects.component.ts->subjects.component.html->profileDetails.component.ts- >profileDetails.component.html
【问题讨论】: