angular2-routing

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

Relative links/partial routes with routerLink

与世无争的帅哥 提交于 2019-12-20 10:22:19
问题 In my app some URLs take the form /department/:dep/employee/:emp/contacts In my sidebar I show a list of all employees, each of which has a [routerLink] which links to that employee's contacts <ul> <li> <a [routerLink]="['/department', 1, 'employee', 1, 'contacts']"></a> <li> <li> <a [routerLink]="['/department', 1, 'employee', 2, 'contacts']"></a> <li> ... </ul> However, with this approach I always need to provide the full path, including all the params (like dep in the above example) which

Unexpected value 'undefined' declared by the module 'AppModule'

本小妞迷上赌 提交于 2019-12-20 10:15:49
问题 What is wrong here? I'm trying to make it work but I get that error in the header. I have included the <router-outlet></router-outlet> in the app.component.html that is being templateUrl called by the app.component.ts , still no luck. app.module.ts : import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule } from '@angular/forms'; import { RouterModule, Routes } from '@angular/router'; import { AppComponent } from './app

How to reload page the whole page in Angular 2? [closed]

我与影子孤独终老i 提交于 2019-12-20 08:59:12
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 2 years ago . How can I reload the current page on Angular via TypeScript? I don't want to change the URL parameters, only to reload. 回答1: This should technically be achievable using window.location.reload() : HTML: <button (click)="refresh()">Refresh</button> TS: refresh(): void { window.location.reload(); }

Routing between modules in Angular 2

那年仲夏 提交于 2019-12-20 08:41:36
问题 I'm writing an application where all features got it's own module (A feature could be a page, or a part of a page). This because we want all features to have it's own domain logic, services, directives and components, i.e. in the dashboard module we got an ChartComponent widget that I don't want to expose to other views like login or profile. The problem is when working with routing in Angular 2 you always routes to a particular component, not a module. In our case, to set up a route for path

Can't bind to 'routerLink' since it isn't a known property

99封情书 提交于 2019-12-20 08:30:27
问题 Recently, I have started playing with angular 2. It's awesome so far. So, i have started a demo personal project for the sake of learning using angular-cli . With the basic routing setup, I now want to navigate to some routes from header, but since my header is a parent to the router-outlet , I receive this error. app.component.html <app-header></app-header> // Trying to navigate from this component <router-outlet></router-outlet> <app-footer></app-footer> header.component.html <a [routerLink

How to return object from service to component in angular

孤街浪徒 提交于 2019-12-20 06:39:53
问题 I want to access particular json in ngOninit. So i have id on click in edit button and with the help of that id i am getting complete object from database like form name , form json which etc. So from the service i want to return that json to ngOninit. Here is service. GetFormById (id: number) { return this.httpClient.get<FormTemplate[]>(this.API_URL + "GetFormTemplate/" + id).subscribe(data => { console.log(data); return data; }); } In console i am getting complete object from database which

Router directives in two places for same purpose

☆樱花仙子☆ 提交于 2019-12-20 05:19:46
问题 I am having a bit of trouble understanding the logic here root-component import { Component } from "angular2/core"; import { TopNavigationComponent } from "./shared/navigation.component"; import { ArcListComponent } from "./arc/arc-list.component"; import { ArcNewItemComponent } from "./arc/arc-new-item.component"; import { RouteConfig } from "angular2/router"; import { ROUTER_DIRECTIVES } from "angular2/router"; @Component({ selector: "ng2-app", template: ` <section class="jumbotron full