angular2-routing

Angular2 router with Http data service through a Resolve with Observable catching 404

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 12:14:46
问题 In my resolve guard I am getting an Http Observable to return the JSON of a user from a particular id . I want to catch an error and reroute to the users overview if the id does not exist. I have seen code that solves that with a Promise, but not with an Observable. I would like to see a solution with an Observable! Currently I get an "EXCEPTION: Uncaught (in promise): Response with status: 404 Not Found for URL: http://127.0.0.1:3000/users/191" since user 191 does not exsist. Here is my code

JavaScript heap out of memory in angular 2

浪子不回头ぞ 提交于 2019-12-22 11:16:05
问题 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,

angular2 target specific router-outlet

只谈情不闲聊 提交于 2019-12-22 11:07:39
问题 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

Angular 2 Routing Error with ModuleWithProviders

怎甘沉沦 提交于 2019-12-22 10:36:39
问题 I'm new in Angular 2 I need help on the routing part. I'm using http://jasonwatmore.com/post/2016/09/29/angular-2-user-registration-and-login-example-tutorial I got an error Exported variable 'routing' has or is using name 'ModuleWithProviders' from external module "/home/frank/angular/node_modules/@angular/core/src/metadata/ng_module" but cannot be named. Here is my code import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { FormsModule

Load nested routes in same router-outlet

与世无争的帅哥 提交于 2019-12-22 10:15:18
问题 I have an Angular 4 application and my private.component.html something like this: <app-breadcrumb></app-breadcrumb> <router-outlet></router-outlet> And my routing: const privateRoutes: Routes = [ { path: '', component: PrivateComponent, children: [ { path: 'dashboard', component: DashboardComponent }, { path: 'settings', component: SettingsComponent }, { path: 'companies', component: CompaniesComponent, children: [ { path: 'add', component: FormCompanyComponent }, { path: ':id', component:

angular 2.0.0-rc.1 + karma: provide RouteSegment

∥☆過路亽.° 提交于 2019-12-22 09:51:05
问题 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

Angular2 - Html link to file download routes to home after click

半腔热情 提交于 2019-12-22 09:37:29
问题 I have an Angular2 application that expose some direct download links to files. The files are located under : [MY_APP_FOLDER]\src\assets\OffertFile An example of the link href is this: /assets/OffertFile/test.xlsx The component.html link example is this: <a href="/assets/OffertFile/test.xlsx" target="_self"> <i class="fa fa-download fa-2x text-primary" aria-hidden="true"></i> </a> The link works, I can download the file. The problem is that once I click the link, the application routes to

How to redirect not-existing link to Home page in Angular 2?

六月ゝ 毕业季﹏ 提交于 2019-12-22 08:46:30
问题 If user input a not-existing link, I want the page redirect to Home page. How can I do it? Thanks @RouteConfig([ {path: '/home', name: 'Home', component: HomeComponent}, {path: '/about', name: 'About', component: AboutComponent}, {path: '/???', name: 'not-found', redirectTo: ['Home']} ]) 回答1: This will redirect all unregistered routes to Home { path: "/**", redirectTo: ["Home"] } 回答2: In Routing of the version v4 name property no more exist. route define without name property. so you should

How to access static data added for particular route in angular 2/4 in service?

痴心易碎 提交于 2019-12-22 08:13:19
问题 const routes: Routes = [ { path: 'somepath', component: SomeComponent, data: { showSidebar: true, title: 'test' } }, { path: 'somepath2', component: SomeComponent2, data: { showSidebar: false, title: 'test2' } } ]; How can I access data object from currently activates route? If my current route is localhost:4200/app/somepath2 then I want to access data: { showSidebar: false, title: 'test2' } 回答1: You could use this.route.snapshot.data Inject router in the constructor import { ActivatedRoute }

Testing a component, which depends on a route param

為{幸葍}努か 提交于 2019-12-22 06:56:01
问题 I have a question about testing a routed component in angular2. Here is a simple component, which depends on a route with a parameter 'foo' . The attribute foo in the component will be set to the value of the parameter. import {Component, OnInit} from '@angular/core'; import {ActivatedRoute, Params} from '@angular/router'; @Component({ selector: 'my-component', templateUrl: './my-component.html' }) export class MyComponent implements OnInit { foo: string; constructor( private route: