angular2-routing

Angular How to change navmenu header based on route

試著忘記壹切 提交于 2019-12-10 14:17:51
问题 I am working on a Dashboard layout in my current project with Angular 4+. When the user navigates between the different sections of the app I need the navmenu header title to update to reflect the current section of the app. As an example when the user visits settings "Page Title" should change to "Settings" The project is based on the .net core 2 Angular template Below is the code I have to makeup the app routing as well as the dashboard routing. navigation.service import { Injectable } from

How to use RouterModule.forRoot() in Angular2 compiler/cli ngc command

依然范特西╮ 提交于 2019-12-10 13:53:39
问题 Let's say i have the following appRoutingModule: export const routes: Route[] = [ { path: '', component: ApplicationlistComponent } ]; @NgModule( { imports: [ ApplicationsModule, RouterModule.forRoot( routes ) ], exports: [ RouterModule ], declarations: [ApplicationlistComponent] } ) export class AppRoutingModule { } When compiling this with the ngc cli command it will give the following error: Error: Error encountered resolving symbol values statically. Calling function 'RouterModule',

Angular 2 final - change route parameter on the URL programmatically

寵の児 提交于 2019-12-10 12:45:30
问题 Assume I'm actually the page "results"... http://server/results;dateFrom=03-11-2016;page=1 Me as the results page, I'd like to load the page 2, but I need to set the URL string on the browser to http://server/results;dateFrom=03-11-2016;page=2 just in case if someone decide to bookmark it. so, how to programmatically change the URL parameter on the Web Browser Address Bar ? ty ! 回答1: You can do it with this code: import { Router } from '@angular/router'; ... constructor(private router: Router

How to get a bit more help perhaps…?

六眼飞鱼酱① 提交于 2019-12-10 12:24:47
问题 I am a little embarrassed to admit I have just spent more time fixing the dread issue: **Syntax Error: Unexpected token <** My mistake was that I had forgotten to add the following to my index.html: <script src="node_modules/angular2/bundles/router.dev.js"></script> However I am including: <script src="node_modules/angular2/bundles/angular2.dev.js"></script> Is there a way of configuring the angular2 dev version to emit more helpful info which would mean that I would get more helpful info

In Angular 2, router.isActiveRoute not working for the first time

♀尐吖头ヾ 提交于 2019-12-10 12:22:51
问题 I use router.isActiveRoute to determine which route is active. At the first time I route to home link or menu link , the route changes but active class isn't added. active class is added at the second click. I think it's bug of Router directive in angular2. Please tell me why and how to fix it? app.ts ... @Component({ selector: 'app', directives: [ROUTER_DIRECTIVES], templateUrl: 'app/components/app.html', styleUrls: ['app/components/app.css'] }) @RouteConfig([ { path: '/', component: Home,

Angular 2 routing in ES5?

北慕城南 提交于 2019-12-10 11:06:41
问题 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

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

本秂侑毒 提交于 2019-12-10 10:48:29
问题 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. 回答1: One way you could do it is

ViewDestroyedError: Attempt to use a destroyed view: detectChanges in Angular 4

柔情痞子 提交于 2019-12-10 08:07:22
问题 i am new to Angular 4 and trying to build a simple routing but when i am trying to redirect on successful register using this.router.navigate(['./admin/login']); so its throwing this error ViewDestroyedError: Attempt to use a destroyed view: detectChanges in console.log . Here is how my register.component.ts file looks like: import { Component, OnDestroy } from '@angular/core'; import { Router } from "@angular/router"; import { ChangeDetectionStrategy } from '@angular/core'; import {

How to use the Querystring instead of ';'

时光毁灭记忆、已成空白 提交于 2019-12-10 04:21:30
问题 I have been writing an internal tool for use by developers using Angular2 beta 15 backed by a C# WebApi. I up the Angular2 version as new versions are released I have been using routing from day 1 but now I need to add optional parameters. Typically this is done via the querystring. However, Angular2 includes optional parameters before the querystring like so: http://www.example.com;a=b;c=4 Originally I figured that would be fine, even though it isn't what I am used to. However, I have now

Proper way to get queryParams with Angular2 RC6

浪子不回头ぞ 提交于 2019-12-10 04:17:18
问题 Please only provide answers current for RC6 and above. I recently attempted to upgrade from RC1 to RC6 and found RouteSegment is gone. After a lot of digging, I've found ActivatedRoute, however it appears to be WAY over complicated for pulling out a raw value from the url. Is the new correct way to read a static query value the following? const id : Observable<number> = this.route.queryParams.map(p => p.id); If so, can some please explain why I need a map and an observable just to pull the