angular2-routing

Angular 2 routing and direct access to a specific route : how to configure Apache?

江枫思渺然 提交于 2019-11-29 06:30:29
问题 I developped a small Angular2 test app which, among other features, leverages routing. It works fine as long as the user first accesses the home page, then navigates to sub pages. If the user tries to directly access a subpage, I got a 404 if I do not configure the web server. This is perfectly normal as there is no "real page" corresponding to the route. I tried to add the following configuration in apache 2.2 to handle HTML5 Push State: <Directory /var/www/html/angular2-sens> Options

Angular 2 dynamically change default route

♀尐吖头ヾ 提交于 2019-11-29 06:24:29
I need to allow the users of my application to change the default route when they want : I have a parameter page where they can select the "page" they want to show first when log on. For exemple for now, they are redirect to Day when they log on, but they want to be able to change that and to be redirect on week or month when they log on if they want. { path: 'planification', component: PlanificationComponent, children: [ { path: '', redirectTo: 'Day', pathMatch: 'full' }, { path: 'day', component: DayComponent }, { path: 'week', component: WeekComponent }, { path: 'month', component:

Angular 2 new Router: How to get router parameters of a child component?

久未见 提交于 2019-11-29 05:55:28
In the latest version of @angular/router 3.0.0-rc.1 The way you get the parameters from a URL/route changed. Based on this documentation you should be able to get the params by subscribing to the params but in my case it seems that is not working. What I want to achieve is to get params into my parent component FROM child routes. For example let's say this is my routes: const routes: Routes = [ { path: 'parent', component: ParentComponent, pathMatch: 'prefix', children: [ { path: ':id', component: ChildComponent } ] } ]; I want to get the id parameter and use it in my ParentComponent. So I'm

In angular 2 how to preserve query params and add additional query params to route

淺唱寂寞╮ 提交于 2019-11-29 05:25:48
问题 For example I am on route /cars?type=coupe and I want to navigate to the same endpoint with additional query params (but keeping existing one). I am trying something like this <a [routerLink]="['/cars']" [queryParams]="{model: 'renault'}" preserveQueryParams>Click</a> The initial query params are preserved (type=cars) but added ones (model=renault) are ignored. Is this expected/correct behavior or is some kind of bug? Looks like preserveQueryParams has priority over queryParams? Is there any

Angular2 AOT with Lazy loading Can't resolve [path to lazy module].ngfactory.ts

强颜欢笑 提交于 2019-11-29 04:22:11
I am trying to convert an App that was already working with Lazy loaded modules into AOT. I am using the @ngtools/webpack toolkit to compile the AOT code, however I am getting into an error that Angular cant find the Lazy loaded module's code as it seems. ERROR in ./src/ngfactory async Module not found: Error: Can't resolve '/Library/WebServer/Documents/envato-teams/src/ngfactory/src/app/components/container/projects.ngfactory.ts' in '/Library/WebServer/Documents/envato-teams/src/ngfactory' @ ./src/ngfactory async @ ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js @ ./src

Passing value between two components (pages) in Angular 2

江枫思渺然 提交于 2019-11-29 04:06:19
I am using Angular 2 (TypeScript) I have two components (actually they are two pages too). They are NOT parent and child relationship. I want to pass a value to second component(page) when I click the link in the first component(page). I know "URL parameters" way through router. But I don't want to show this parameter in the link. Is there any other way? Thank you! The canonical way is to establish an injectable service and inject the service into any components that need the data. Since the service is a singleton, the components will be accessing the same data. It shouldn't matter that they

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

那年仲夏 提交于 2019-11-29 02:06:49
问题 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';

provideRouter and RouterConfig not found in new @angular/router 3.0.0-alpha.3^

為{幸葍}努か 提交于 2019-11-29 01:58:10
I am migrating an angular2 app to RC2 and trying to use the router's version 3 alpha. I have followed the set up of the plunker given by the angular docs for routing But i keep getting the following errors: /@angular/router/index"' has no exported member 'provideRouter' /@angular/router/index"' has no exported member 'RouterConfig' when trying to use the following imports in my app.router.ts file: import { provideRouter, RouterConfig } from '@angular/router'; I am using typescript in visual studio with commonjs module format. Here are the dependecies from my packages.json "@angular/common": "2

Host Angular2 app with routing in Azure

随声附和 提交于 2019-11-29 01:15:56
问题 I'm developing an app in Angular 2 using the angular cli. The app works fine, and runs ok when I deploy it in Azure, but the routing doesn't work. I can access my app via "myapp.azurewebsites.net", but if I try "myapp.azurewebsites.net/settings" I get an 404 error. I have found a lot of guides with a lot of different ways to make different servers route everything to one index-file, but none have worked, at all. Like providing an web.config file, configuring node or express server, and both

How to apply css class to a component element when it's created by router-outlet?

試著忘記壹切 提交于 2019-11-29 01:01:50
I have DOM that looks something like this: <app> <router-outlet></router-outlet> <project>...</project> </app> where project element is inserted by the router. How do I add a class to this element? Assuming you always want the class applied to this component, you can use host in your component metadata: @Component({ selector:'project', host: { class:'classYouWantApplied` } }) Resulting in: <app> <router-outlet></router-outlet> <project class="classYouWantApplied">...</project> </app> The key is /deep/ keyword: :host /deep/ router-outlet + project { display: block; border: 10px solid black; }