Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why does PrimeNg expect a router? How can I workaround this in beta14? #831

Closed
JakeSummers opened this issue Sep 1, 2016 · 4 comments
Closed

Comments

@JakeSummers
Copy link
Contributor

Good Morning,

Question 1: I am not using a router in my Application, but PrimeNg expects a router to be injected. Why is this? Could this be made an optional provider?

Question 2:: What is the easiest way to pass in a dummy router?

In PrimeNG 1.0.0-beta.12 and below, I could do the following, to trick the components into thinking that there was a router:

@Component({
    selector: 'my-thing',
    template: require( './thing.component.html' ),
    directives: [Tree, ContextMenu ],
    providers: [{provide: Router, useValue: {}}]
})
export class Thing implements OnInit {

In PrimeNG 1.0.0-beta.13, I moved the Router into the AppModule and the trick continued to work:

@NgModule({
    bootstrap: [AppComponent],
    declarations: [
        ...
    ],
    imports: [
        ...
        RouterModule,
        DialogModule,
        ...
    ],
    providers: [ // expose our Services and Providers into Angular's dependency injection
        ...
        {provide: Router, useValue: {}}
        ...
    ]
})
export class AppModule {
}

When I upgrade to PrimeNG 1.0.0-beta.14 this trick no longer works. What is the cleanest workaround?

@cagataycivici
Copy link
Member

That is required for menu components to support routerLink functionality so that clicking on an item navigates to a view defined by the router, we are open to suggestions though. Not sure about dummy router.

@tanspac
Copy link

tanspac commented Mar 3, 2017

I ran into a similar issue. In my case my application is not using routing. I agree that router should be made optional since there is only one place in the code where the router is actually used. To work around this I created my own router service:

export class Router
{
   constructor(){}
   public navigate(route: any[]):void
   {
       // Do nothing
   }
}

Then I modified my systemjs.config.js to point @angular/router to my new router. This worked great and I can use the component without needing the router.

@yugandhar113
Copy link

use as below

@component({
selector: 'app',
template: <p-menubar [model]="items"></p-menubar>,
directives: [Menubar],
providers: [{provide: Router, useValue: {}}]
})

@cagataycivici
Copy link
Member

Menu components require a router, not aware of a may to make it optional I'm afraid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants