2016-07-16 9 views
7

yüklemek için birincil çıkış bulamıyorum Uygulamamda 3.0.0-beta.1 yönlendirici kullanarak benim uygulamada yönlendirmeye çalışıyorum, uygulama çalışıyor ancak konulardaki 'sonraki' düğmesini tıklattığımda .component.html 'profileDetails.component.html' içeriğini almak için sabırsızlanıyorum. Örneğin bir plunkr oluşturdum. burada: http://plnkr.co/edit/jR3jnC6CzmRVCoVFrn1W?p=preview Sanırım kullandığım açısal 2 malzeme düğmesinden dolayı plunkr üzerinde çalışmıyor ama sanırım kimsenin nerede yanlış gittiğimi söyleyebilir miyim? İşte benim main.ts:Hata: 'ProfileDetailsComponent'

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 
]); 

İşte app.routes.ts var:

@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] 
}) 

akışı bu app gibi biraz geçerli:

İşte
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) 
]; 

benim app.component.ts var .component.ts-> basicCard.component.ts-> basicCard.component.html-> subjects.component.ts-> subjects.component.html-> profileDetails.component.ts-> profileDetails.component.html

+0

[Angular2 Yönlendirici hatası: birinci çıkış bulamazsa 'Ana' yük] (http://stackoverflow.com/questions/37950413/angular2-router-error-cannot-find-primary -outlet-to-load-homepage/37951430 # 37951430) –

+0

Olası kopyası [Angular2 Router hatası: 'HomePage' yüklemek için birincil çıkış bulamıyor] (https://stackoverflow.com/questions/37950413/angular2-router-error -yok-bulmak-birincil-çıkış-yük-ana-sayfa) – ishandutta2007

cevap

10

app.component'unuzda yönlendirici çıkış yönergesi eksik.

@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

+0

Ama ben basicCard.component.html içinde şablon: app.component.ts & ekledim, Plunkr bağlantısını sağladım soru ... –

+2

problemi var o yönlendirici çıkışı bir ngIf içinde. –

+0

@HimanshiGupta, yine de üst düzey bileşende bir yönlendirici çıkışı sağlamanız gerekiyor. Bu, Açısal'nın bulamamasından şikayet ettiği "birincil çıkış" dır. – jessepinho