angular-routing

What is the easiest way to get Current Route Path Name in Angular?

回眸只為那壹抹淺笑 提交于 2019-12-20 17:33:03
问题 I was looking for a good way to get the current route's path name. This was the easiest I could find. this.route.snapshot.firstChild.url[0].path Is there a better way? Thanks! 回答1: Thanks everyone for the answers. Here is what I found that I had to do. router.events.subscribe((event: Event) => { console.log(event); if (event instanceof NavigationEnd ) { this.currentUrl = event.url; } }); 回答2: easiest way to find current path is either you directly use this.router.url or you can check current

Change a single route parameter on the current route in Angular 2

有些话、适合烂在心里 提交于 2019-12-20 11:12:12
问题 Is it possible to change a single route parameter in the current route, while keeping all the other parameters? This is for use in a paging component, which will route to a new page while keeping the other parts of the current route the same. Some examples: Default page to page 2: orders?foo=foo&bar=bar > orders?foo=foo&bar=bar&page=2 Default page to page 2 (child): orders/;foo=foo;bar=bar > orders/;foo=foo;bar=bar;page=2 Page 2 to 3 on child and parent with parameters: orders/;foo=foo;page=2

Change a single route parameter on the current route in Angular 2

别等时光非礼了梦想. 提交于 2019-12-20 11:11:28
问题 Is it possible to change a single route parameter in the current route, while keeping all the other parameters? This is for use in a paging component, which will route to a new page while keeping the other parts of the current route the same. Some examples: Default page to page 2: orders?foo=foo&bar=bar > orders?foo=foo&bar=bar&page=2 Default page to page 2 (child): orders/;foo=foo;bar=bar > orders/;foo=foo;bar=bar;page=2 Page 2 to 3 on child and parent with parameters: orders/;foo=foo;page=2

Angular router: how to replace param?

家住魔仙堡 提交于 2019-12-20 10:41:57
问题 Let's suppose I've got 3 urls: /:projectId/info , /:projectId/users , /:projectId/users/:userId/profile . All of them have param projectId . UI has a component to switch from one project to another. So I need: Get current URL Change param by name (e.g. projectId) Navigate to new url So I need something like this.router.replaceParam(currentUrl, {projectId: 'project_id_2'}) which will transform /project_id_1/users/user_id_1/profile into /project_id_2/users/user_id_1/profile (and any other URL

Using 'controller as' with the ui-router isn't working as expected

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-20 10:03:46
问题 I have the following state setup for a page using an abstract state and the controller as syntax: # Details page route .state 'title', url: '/title', abstract: true, template: '<ui-view/>', .state 'title.show', url: '/:titleId', templateUrl: 'title/show.html' controller: 'Title as t' For the purpose of this demo lets say I assign a variable to the 't' instance of the 'Title' controller and I do this inside of the Title controller function. angular.module('title').controller 'Title', ['$state'

How to handle routing in Angular 5+ Service Workers?

一世执手 提交于 2019-12-20 08:13:20
问题 In previous versions of the Angular service worker implementation, one of the config options was "routing" . This can be seen in this unanswered SO question, was referenced in this Angular CLI issue, and the best remaining documentation seems to be the blog post by Stephen Fluin (on the Angular team), as well as the I/O talk from Alex Rickabaugh (from Google). With Angular 5, the ServiceWorkerModule has been well built-out, and most of the configuration can now be handled using the ngsw

How to handle routing in Angular 5+ Service Workers?

谁说我不能喝 提交于 2019-12-20 08:12:23
问题 In previous versions of the Angular service worker implementation, one of the config options was "routing" . This can be seen in this unanswered SO question, was referenced in this Angular CLI issue, and the best remaining documentation seems to be the blog post by Stephen Fluin (on the Angular team), as well as the I/O talk from Alex Rickabaugh (from Google). With Angular 5, the ServiceWorkerModule has been well built-out, and most of the configuration can now be handled using the ngsw

Angular - Sidebar not to show in Login but to show in Dashboard - Angular Routing

孤人 提交于 2019-12-20 04:37:23
问题 How to hide sidebar in login page? How can I open login page first without sidebar and then after successful login will redirect on dashboard of template in Angular 4. 回答1: The best way to do this is to design a Shell Component(suggested by Deborah Kurata in this ngConf talk) which will house your View After the user logs in. The template of this Shell Component will house the Side Bar. The template of this Shell Component will also have a router-outlet for internal routing. So your Routes

angular service available at configuration phase

╄→гoц情女王★ 提交于 2019-12-20 04:29:31
问题 I want to move some of the repetitive logic out in a reusable service, which must be available in a config phase . And possibly have access to $xxxProvider dependency injections too. Is such thing possible? Can one do this with factory/provider/service/constant ? To be specific, when I define my routes with ui-router , I noticed that routes for CRUD are all the same, except for the names of the resources. So i'd like to move this logic of configuring a CRUD route somewhere to make route

Angular updating and clearing factory variables

社会主义新天地 提交于 2019-12-20 02:52:35
问题 I'm creating a single page app in which a user searches for a term, the result gets saved in a variable, and a new page is routed that displays the result. I have this functionality working, however I want the variable to be cleared when the user returns to the previous page and most importantly when the user logs out. What's the proper way to do this? I want the factory to save things for certain pages that I want, and clear them for certain pages I don't want like "home" or "logout".