angular2-routing

Angular 2 Router Using BehaviorSubject Observable in Resolve

廉价感情. 提交于 2019-12-05 23:53:21
问题 I'm trying to set up my router config using a Resolve that returns an Observable from a BehaviorSubject. I've tried this in both angular 4.0.0-beta8 and angular 2.4.8+router 3.4.8 Here's my service: @Injectable() export class MyService { private _data: BehaviorSubject<Array<string>> = new BehaviorSubject(undefined); constructor() {} public getData(): Observable<Array<string>> { this._data.next(['test1', 'test2', 'test3']); let asObservable = this._data.asObservable().delay(1000); asObservable

Angular2 How to display error page while keeping route

你说的曾经没有我的故事 提交于 2019-12-05 23:23:22
问题 Apologies if this is somewhere else, but my normal searching tactics have failed me. I'd like to display a custom error page when I receive a 500 from the API. I'm using restangular and have a response interceptor that redirects to the error page when I receive the 500, using: this.router.navigate(['/error']); This all works. However, I'd like to keep the previous URL in the browser navigation bar so that when the user refreshes it tries the previous page again, whereas right now they have to

angular2 target specific router-outlet

我的梦境 提交于 2019-12-05 22:33:40
I have an app that has a base router-outlet that is used as a base for the entire app. then a child router-outlet that is used once a user is logged in to display any components loaded as a result of clicking on a navigation link clicked that is based in the base router-outlet. I want to be able to target the child router-outlet when a navigation link is clicked in the base template. When I click on a nav item in the base template, it loads the component in the base router-outlet. That makes good sense to me. I would like to know how I can click a nav item in the base template and have the

Angular 2.0, how to detect route change on child component

醉酒当歌 提交于 2019-12-05 21:12:10
问题 How can I detect a route change on a child component?. This is what I have tried, but I only see the app component trace the route change. I want to be able to detect when the url change from e.g. #/meta/a/b/c to #/meta/a/b/c/d in the MetaDetailView component. @RouteConfig([ { path: '/', name: 'Home', redirectTo: ['Meta']}, { path: '/meta/...', name: 'Meta', component: MetaMainComponent, useAsDefault: true}, ...other routes..., ]) export class AppComponent { constructor(private _router:

JavaScript heap out of memory in angular 2

拈花ヽ惹草 提交于 2019-12-05 20:09:04
I am using Angular CLI. Please check my CLI info @angular/cli: 1.2.1 node: 6.10.0 os: win32 x64 @angular/animations: 4.1.1 @angular/common: 4.0.0 @angular/compiler: 4.0.0 @angular/compiler-cli: 4.0.0 @angular/core: 4.0.0 @angular/forms: 4.0.0 @angular/http: 4.0.0 @angular/platform-browser: 4.0.0 @angular/platform-browser-dynamic: 4.0.0 @angular/router: 4.1.1 When I use ng serve --aot I am getting the following error. Last few GCs 893427 ms: Mark-sweep 1344.1 (1434.3) -> 1339.9 (1434.3) MB, 925.7 / 0.0 ms [allocation failure] [GC in old space requested]. 894468 ms: Mark-sweep 1339.9 (1434.3) ->

How to navigate in angular2 to new tab

☆樱花仙子☆ 提交于 2019-12-05 19:03:01
Is there a parameter to provide to the router so that router.navigate() will open in a new tab/window in browser? Create routes just like instructed here . Set up your app-routing.module.ts ( or just put it in app.module.ts ), place the <router-link> in your app.component.html . Now, to open a new window from the main page, ( or whatever sub-routes you have created ) just call a function, handled in the main component, that will point to the url of the sub-component route that you setup for the new window. Example snippits: app-routing.ts import { NgModule } from '@angular/core'; import {

Angular2 Can't resolve all parameters for RouterOutlet: (RouterOutletMap, ViewContainerRef, ?, name)

落花浮王杯 提交于 2019-12-05 18:33:48
I'm totally new to any JS framework. Just started learning Angular 2. I'm doing some basic app for internship. From angular app I post name to Java controller, that get's info needed and sends it back. Basically fun happens when name is 'Dave' or 'Hal'. All looks fine, but when I run server and try to get to my app, I get EXCEPTION: Error: Uncaught (in promise): Can't resolve all parameters for RouterOutlet: (RouterOutletMap, ViewContainerRef, ?, name). As far as I can tell from documentation, the missing parameter is componentFactoryResolver . How to get rid of this error and run it all

angular 2.0.0-rc.1 + karma: provide RouteSegment

懵懂的女人 提交于 2019-12-05 18:30:34
When a component is injected with RouteSegment, just providing the RouteSegment in the test is not enough: component.ts: export class ComponentToTest { private param: string; constructor(routeSegment: RouteSegment) { this.param = routeSegment.getParam('param'); this.getData(); } } component.spec.ts: import {Router, RouteSegment} from '@angular/router'; import {it, inject, beforeEachProviders} from '@angular/core/testing'; import {ROUTER_FAKE_PROVIDERS} from '@angular/router/testing'; import {ComponentToTest} from './component'; describe('ComponentToTest', () => { beforeEachProviders(() => [

Good template strategy for authentication in Angular 2

怎甘沉沦 提交于 2019-12-05 18:16:31
问题 I currently have an Angular 2 app up and running that looks as follows: App.component is bootstrapped when visiting the site. The template for App.component has all component tags (for example menu.component, search.component and the router-outlet). What I basically need is the following: currently a visitor is directly redirected to the Login page because the user needs to login. He is still able to see the menu and all components that are only there for logged in users. What would be the

How can I navigate to lazy loaded module child routes?

早过忘川 提交于 2019-12-05 18:01:56
I am trying to lazy load module with child routes declared in it's routing configuration file, The lazy module loaded successfully but I can't navigate to it's child routes. I am using the technique as if it were a eagerly loaded module. I declared path and inside it it's children. Please see 'moduleB' routing file in the Plunker The link button is trying to navigate to the child route and load CmpC. but it fails. Here is my root module routing decalration: { path: 'feature-b', loadChildren:'src/featureB/featureB.module#FeatureBModule' , pathMatch: 'full'} Here is my lazy loaded module routing