How to go to angular2 tab to new tab

Is there an option to provide the router so that router.navigate () opens in a new tab / window in the browser?

+2
source share
1 answer

Create the routes as described here .

Set up your app-routing.module.ts (or just put it in app.module.ts ), put <router-link> in your app.component.html .

Now, to open a new window from the main page (or any other sub-items that you created), just call the function processed in the main component, which will point to the URL of the subcomponent route that you are setting for the new window.

Fragment example:

application-routing.ts

 import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { MainComponent } from './main/main.component'; // main window import { JclInfoComponent } from './jcl-info/jcl-info.component'; // new window/tab const appRoutes: Routes = [ { path: '', component: MainComponent }, // main route { path: 'openJcl', component: JclInfoComponent } // new window route ]; @NgModule({ imports: [ RouterModule.forRoot( appRoutes ) ], exports: [ RouterModule ] }) export class AppRoutingModule {} 

app.component.html

 <router-outlet> <!-- Just showing you that you can put things inside this. --> <template ngbModalContainer></template> </router-outlet> 

main.component.html

 <button (click)="testMe()">myLabel</button> 

main.component.ts

 public testMe() { window.open( "openJcl" ); } 
+1
source

Source: https://habr.com/ru/post/1013604/


All Articles