angular2-routing

Implementing Dynamic Routing in Angular2 (Typescript) [duplicate]

天大地大妈咪最大 提交于 2019-12-30 01:30:19
问题 This question already has answers here : Async load routes data and build route instruction for Angular 2 (4 answers) Closed 3 years ago . 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

Run a Service Function inside an Angular Routing Module class

时间秒杀一切 提交于 2019-12-29 10:02:47
问题 So the basic story... At the top of this SPA is a 'top-bar' component, and inside that component is a search-bar component. Now - there are a few 'landing pages' where we want to turn this search-bar component off. I understand the process of using this through a service (since the 'landing pages' in question aren't directly connected to the search-bar component. And in and of itself - I had this working... The problem comes from the fact that if you land on one of these landing pages, and

Angular 2 async pipe not rendering/updating Observable data automatically

孤街浪徒 提交于 2019-12-29 09:13:29
问题 I am facing an issue with the Angular2 router and an async pipe. I am trying to render an RxJs Observable and the data does not render automatically. One has to click on the link for the route for the data to render. Here is the root app: import {bootstrap} from 'angular2/platform/browser'; import {HTTP_PROVIDERS} from 'angular2/http'; import {ROUTER_PROVIDERS} from 'angular2/router'; import {AppComponent} from './app.component.ts'; bootstrap(AppComponent, [HTTP_PROVIDERS, ROUTER_PROVIDERS]);

Angular 2 async pipe not rendering/updating Observable data automatically

核能气质少年 提交于 2019-12-29 09:13:12
问题 I am facing an issue with the Angular2 router and an async pipe. I am trying to render an RxJs Observable and the data does not render automatically. One has to click on the link for the route for the data to render. Here is the root app: import {bootstrap} from 'angular2/platform/browser'; import {HTTP_PROVIDERS} from 'angular2/http'; import {ROUTER_PROVIDERS} from 'angular2/router'; import {AppComponent} from './app.component.ts'; bootstrap(AppComponent, [HTTP_PROVIDERS, ROUTER_PROVIDERS]);

Angular2 routing - adding the hashtag using LocationStrategy not working?

做~自己de王妃 提交于 2019-12-29 08:52:07
问题 I'm following the simple quickstart app from the Angular2 docs and I'm using a spring backend to run it. My problem is that the angular router ditched the hashtag from the URL so what should have been example.com/#/dashboard is now example.com/dashboard . I am using the LocationStrategy method specified in a bunch of posts on StackOverflow. Below is my simple example: File: main.ts ///<reference path="../node_modules/angular2/typings/browser.d.ts"/> import {bootstrap} from 'angular2/platform

Angular 2.0.2: ActivatedRoute is empty in a Service

核能气质少年 提交于 2019-12-29 05:44:48
问题 I want to use ActivatedRoute to get route params in a service like I would do in a Component. However, when I inject the ActivatedRoute object in a Service it contains an empty params variable I've created a plunker that reproduces the behaviour: http://plnkr.co/edit/sckmDYnpIlZUbqqB3gli Note that the intention is to use the parameter in the service and not in the component, the way the plunker is set up is purely to demonstrate the issue. Component ( test is retrieved): export class

Angular 2 Routing Does Not Work When Deployed to Http Server

限于喜欢 提交于 2019-12-29 03:25:08
问题 I am going to develop a simple Angular 2 application. I have created a project with routing, using Angular CLI and added several components to the app using 'ng generate component ' command. Then I specified routing in the app-routing.module.ts as following. import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import { HomeComponent } from './home/home.component'; import { AboutComponent } from './about/about.component'; import { UserComponent }

how to read http status code error in component

纵饮孤独 提交于 2019-12-29 01:26:26
问题 I know this has been asked before but I can't seem to find the answer, how to read status code from http..? this.bookingService.save(this.param) .subscribe( data => swal({ "title": "Succes!", "text": "Your data saved", "type": "success", "confirmButtonClass": "btn btn-secondary m-btn m-btn--wide" }), error => console.log('error'), () => this.router.navigate('Succes') ); 回答1: You can get the status code from the error, this.bookingService.save(this.param).subscribe( data =>{ console.log(data);

How to use the activated route's data DIRECTLY in the HTML template containing the RouterOutlet?

纵饮孤独 提交于 2019-12-28 06:52:23
问题 This one took me a while to figure out, so I hope to save someone's time by sharing the solution in the SO's Q&A way. Here it goes: Goal I have an Angular8 web application, where I use the RouterModule to navigate between the components. Here is how my routes are defined: const routes: Routes = [ { path: 'moo', component: AppMooComponent, data: { title: 'Moo Section', desc: 'Moo is the first example component.' } }, { path: 'boo', component: AppBooComponent, data: { title: 'Boo Section', desc

Angular 2: Passing Data to Routes?

一个人想着一个人 提交于 2019-12-28 03:51:09
问题 I am working on this angular2 project in which I am using ROUTER_DIRECTIVES to navigate from one component to other. There are 2 components. i.e. PagesComponent & DesignerComponent . I want to navigate from PagesComponent to DesignerComponent. So far its routing correctly but I needed to pass page Object so designer can load that page object in itself. I tried using RouteParams But its getting page object undefined . below is my code: pages.component.ts import {Component, OnInit ,Input} from