Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Cannot find primary outlet to load 'ProfileDetailsComponent'

I am trying to use routing in my application, using router version 3.0.0-beta.1, the application is running but when I click the 'next' button in subjects.component.html I am looking forward to getting the content of 'profileDetails.component.html'. I've created a plunkr eg. here : http://plnkr.co/edit/jR3jnC6CzmRVCoVFrn1W?p=preview It doesn't work on plunkr though due to the angular 2 material buttons etc that I'm using I guess, but can anyone tell me where am I going wrong? Here's my 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
]);

Here's 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)
];

Here's my 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]
})

The flow is somewhat like this app.component.ts->basicCard.component.ts->basicCard.component.html->subjects.component.ts->subjects.component.html->profileDetails.component.ts->profileDetails.component.html

like image 994
Himanshi Gupta Avatar asked Jul 16 '16 07:07

Himanshi Gupta


1 Answers

In your app.component you are missing the router outlet directive.

@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

like image 200
KB_ Avatar answered Sep 29 '22 10:09

KB_