angular2-routing

Angular 2 @angular/router 3.0.0-alpha.7 - Accessing Multiple Parameters

妖精的绣舞 提交于 2019-12-06 14:27:43
I am just trying the new router in Angular 2 announced recently i.e. Angular 2 @angular/router 3.0.0-alpha.7 I know that in new router we can access route parameters using below code: this.activatedRoute.params .map(params => params['id']) .subscribe((id) => { //use param id }); Can anyone please guide how do we handle the case in which we have multiple multiple parameters in our route? I mean how do we retrieve the values of multiple parameters from route. One way you could do it is using Parameter handling and Destructuring like this: this.activatedRoute.params .map(params => [params['id'],

angular2 programmatically import components from resource files

强颜欢笑 提交于 2019-12-06 14:14:06
问题 Angular2 rc.4 - rc.5 Can we import components programmatically ? for example if i have following import statements i want to convert import {HelloComponent} from './hello.component'; import {IncComponent} from './inc.component'; is it possible to import components on runtime using system.import from the resource file as following ? any suggestion is appreciated I have an array let routes: RouterConfig = []; let routeArr =[ {path: 'hello', component:'HelloComponent', resource:'./hello

Angular 2.0.0-rc3: partial route matching with routerLinkActive

被刻印的时光 ゝ 提交于 2019-12-06 11:00:55
问题 I'm using routerLinkActive in my primary routing. <a [routerLink]="/user" routerLinkActive="active">Bob</a> When the URL is /user , the active class will be added to the a tag, but under the primary route, I also have a few secondary routes, so when the URL is /user/aa , the active will be removed. I hope that when the URL is either /user/aa or /user/bb , the primary route's class active still exists. What should I do? 回答1: Add [routerLinkActiveOptions]="{ exact: false }" As far as I know

Angular 2 pass array to router queryString

走远了吗. 提交于 2019-12-06 09:18:23
I would like pass array ids: [1, 2, 3] to router query string like this: http://...some-url?ids=1&ids=2&ids=3 , but when I try to use const queryParams = { ids: [1, 2, 3] }; this.router.navigate(['/some-route'], { queryParams }); the result is http://...some-url/some-route?ids=1%2C2%2C3 Is there way to add query params with same key? Alexander Pisarev Looks like there is a bug in the router. Please, check this answer: https://stackoverflow.com/a/42505212/7634393 router.navigate is waiting for a named 'queryParams' value. So, this should work. const queryParams = { ids: [1, 2, 3] }; this.router

Angular 4 losing subscription with router paramMap using switchMap

…衆ロ難τιáo~ 提交于 2019-12-06 08:11:14
问题 Using the latest version of Angular I have a very small, simple application - see below: The forecast detail component looks like the following: public getForecastData(forecastId) : Observable<any> { return this.http.get<any>('/api/forecasts/' + forecastId + '/data'); } ngOnInit() { this.route.paramMap .switchMap( params => { return this.getForecastData(params.get('id')) }) }) .subscribe( (data) => { // business logic here }); The issue I'm having is that if the getForecastData call fails

Angular 2 Dynamic Page Header and Footer

微笑、不失礼 提交于 2019-12-06 07:59:38
问题 The following is what is included in my app.component.html <lmenu></lmenu> <header></header> <router-outlet></router-outlet> <footer></footer> However my login and register pages are both rendered through this module and they only require the router-outlet. How an dynamically not include the lmenu, header, and footer selectors for the login and register views? Thanks in advance. 回答1: <lmenu *ngIf="isLogin"></lmenu> <header *ngIf="isLogin"></header> <router-outlet></router-outlet> <footer

Angular2 routing - manual url navigation

戏子无情 提交于 2019-12-06 07:57:41
I have a very simple app My app.component.html looks like this: <a [routerLink]="['/Test']">CLICK ME</a> <div class="main-container"> <router-outlet></router-outlet> </div> My app.component.ts looks like this: @Component({ selector: 'app', templateUrl: 'app/app.component.html', directives: [HomeComponent, TestComponent, ROUTER_DIRECTIVES] }) @RouteConfig([ {path: '/', component: HomeComponent, as: 'HomeComponent'}, {path: '/test', component: TestComponent, as: 'Test'} ]) export class AppComponent { } To navigate to my app, I go to http://localhost/app Which works perfect, it navigates me to my

How to use routerLinkActive with empty routerLink

╄→尐↘猪︶ㄣ 提交于 2019-12-06 07:01:39
问题 I have the following tab bar links and the first one is supposed to be empty: <nav md-tab-nav-bar> <a md-tab-link [routerLink]="'./'" routerLinkActive #rla="routerLinkActive" [active]="rla.isActive"> My tab </a> ... </nav> The link works fine but the active state is not triggered. What is the proper way to handle empty routerlink for the tab to be activated? 回答1: Try this instead <a [routerLink]=" ['./'] " routerLinkActive="active" [routerLinkActiveOptions]= "{exact: true}"> My tab </a> https

Angular 2 routing in ES5?

孤街醉人 提交于 2019-12-06 06:53:33
The Angular 2 ES5 cheat sheet says to do this: var MyComponent = ng.router.RouteConfig([ { path: '/:myParam', component: MyComponent, as: 'MyCmp' }, { path: '/staticPath', component: ..., as: ...}, { path: '/*wildCardParam', component: ..., as: ...} ]).Class({ constructor: function() {} }); However, I can't figure out how to specify the @Component stuff on that class so that I can actually instantiate it. For example, ng.router.RouteConfig([...]).Component({}) throws an exception because the result of .RouteConfig doesn't have a .Component method. Similarly, the result of .Component doesn't

Angular 2 Router how to hide browser url parameter Id's and give alias names

我只是一个虾纸丫 提交于 2019-12-06 06:25:51
How do I route to employeeDetail/23 but represent to the user an alias URL like /EmployeeDetails ? Background I'm trying to implement Angular 2 routing and when I went to the detail section I see: http://localhost:3444/employeedetail/23. Here I want to hide that 23 on the browser URL. Example http://plnkr.co/edit/QgehylornOgXhTaZX8Yn?p=preview {path: 'crisis-center/:id/:id2', component: CrisisDetailComponent} I want to hide those IDs on the browser URL and instead present an alias route name. Prakash use "skipLocationChange" from where you are calling this route (assuming 23 is your empId):