angular2-routing

Implementing Dynamic Routing in Angular2 (Typescript) [duplicate]

蹲街弑〆低调 提交于 2019-11-30 05:12:38
This question already has an answer here: Async load routes data and build route instruction for Angular 2 4 answers RouteConfig class which can be used to decorate a component (@RouteConfig) with routing capabilities has certain route definitions defined for that component. Now, the catch is to have these route definitions injected at runtime (dynamically). The reason being, let's say I have an application wherein I have to display (UI) and define (decorate) 'n' number of routes, each which corresponds to the account for which the application is loaded and consequently the rights that are

Can't resolve all parameters for Router: (?, ?, ?, ?, ?, ?, ?) in Angular RC 5 when unit testing

断了今生、忘了曾经 提交于 2019-11-30 04:41:16
I just upgraded to Angular RC 5 and now all component that uses 'ROUTER_DIRECTIVES' fails with 'Can't resolve all parameters for Router: (?, ?, ?, ?, ?, ?, ?)' when I try to unit test the component. import { inject, addProviders } from '@angular/core/testing'; import { ComponentFixture, TestComponentBuilder } from '@angular/core/testing'; import { Component } from '@angular/core'; import { ROUTER_DIRECTIVES, Router } from '@angular/router'; import { HomeComponent } from './home.component'; import { UserService } from '../_services/user.service'; describe('Component: Home', () => { beforeEach((

Angular 2 get current route in guard

雨燕双飞 提交于 2019-11-30 04:39:42
I have an AccessGuard class in my project which its work is to determine if user can access to the route or not. I used the router.url to get the current route but the url returns the route before navigation to the new route like I'm in the users route and I click on the candidates route so the url returns users instead of candidates which I want that to validate access to the route this is my route file: const routes:Routes = [ { path:'', component:PanelComponent, canActivate:[AuthGuard,AccessGuard], canActivateChild:[AuthGuard,AccessGuard], children:[ { path:'dashboard', component

End interval when route changes in Angular 2

半城伤御伤魂 提交于 2019-11-30 04:02:09
问题 I start a timer in an Angular 2 component which is inside a router outlet. setInterval(() => { ... }, 10000); When I leave the route in which the component is embedded the timer isn't quit. How can I achieve that? 回答1: This should do it: routerOnActivate() { this.timer = setInterval(()=>{ ... }, 10000); } routerOnDeactivate() { clearInterval(this.timer); } 回答2: You could clear the interval from this hook. Mine is controlled from the component/view. export classTestInterval implements OnInit,

Angular 2 Hosted on IIS: HTTP Error 404

时光怂恿深爱的人放手 提交于 2019-11-30 03:50:31
I have simple app with one component that expects certain parameters from url. there is only one route in the application: const appRoutes: Routes = path: 'hero/:userId/:languageId',component: HeroWidgetComponent }]; In the Index.html, I have this in the header <base href="/"> I am using webpack and the application runs fine on development environment, when browsing the url: http://localhost:4000/hero/1/1 . However, when building the app for production and getting the distribution files, then hosting that on IIS. I get the following Error when trying to browse the same url: HTTP Error 404.0 -

Angular2 Get router params outside of router-outlet

孤人 提交于 2019-11-30 03:49:18
问题 I have a dashboard application which consists of a treeview component (which lists various content nodes) and a dashboard-edit component which renders some editable content depending on which branch of the tree is selected. e.g. The tree is like this: - Football - - Premier League - - - Arsenal - - - Chelsea - - - ...etc - - Championship - - - Derby - - - ...etc You click 'Arsenal' in the tree and it renders some content for that team in an editable panel on the page. The component which

Angular2 Router link not working

浪子不回头ぞ 提交于 2019-11-30 03:19:15
问题 My router link works from the root component and the same link not working if I move the links to child component. The plunker code shows the working link and non working link. Thank you in advance. The below is the not working links. //our root app component import {Component} from '@angular/core' @Component({ selector: 'my-menu', template: ` <div> <a routerLink="/comp11" routerLinkActive="active">Crisis Center</a> | <a routerLink="/comp12" routerLinkActive="active">Heroes</a> | <a

Hide elements based on routing in Angular2 rc1

放肆的年华 提交于 2019-11-30 03:00:35
I have some elements I want on every page except the login page. I'd like to use ngIf or possibly the hidden property of the elements to hide those elements when the user is on the login page. I have tried this: <div [hidden]="router.isRouteActive(router.generate('/login'))"> based on this question and answer: In Angular 2 how do you determine the active route? And have also tried this: <div *ngIf="!router.isRouteActive(router.generate('/login'))"> but haven't had any success. For reference here is the component that matches this html. import { Component, OnInit } from 'node_modules/@angular

Angular2 Lazy Loading Service being Instantiated Twice

蹲街弑〆低调 提交于 2019-11-30 02:44:27
问题 I just switched my application over to be lazy-loaded today. I have a SharedModule that exports a bunch of services. In my AppModule , I import SharedModule because AppComponent needs access to a few of the shared services. In another module FinalReturnModule , I import SharedModule . In one of my services, I put a console.log('hi') in the constructor. When the app first loads, I get hi to the console. Whenever I navigate to a page within the FinalReturnModule I get hi again. Obviously, since

Angular2 - page refresh 404ing when hosted in Azure

时光总嘲笑我的痴心妄想 提交于 2019-11-30 02:40:45
问题 I am working on an Angular2 app. It uses "@angular/common": "2.0.0-rc.4" and "@angular/router": "3.0.0-beta.2". My problem is that when I use the browser refresh on some of the pages I see an error saying... " The resource you are looking for has been removed, had its name changed, or is temporarily unavailable." This also happens if I hit the url directly. An example url is... https://tilecasev2.azurewebsites.net/profile/therichmond However if you view pages via the homepage they work ok but