angular2-routing

Angular 2 RouterStateSnapshot not returning correct url

心不动则不痛 提交于 2019-12-12 05:15:00
问题 I'm trying to get the redirect after login working based on the documentation from angular. https://angular.io/docs/ts/latest/guide/router.html#!#teach-authguard-to-authenticate I got basically the same setup albeit that some filenames are different. The problem is that when i log the RouterStateSnapshot url in the authGuard, it wil always output the first route from app-routing.module.ts ('/countries') instead of e.g. /countries/france/34 authGuard canActivate(route: ActivatedRouteSnapshot,

ViewChild - Angular 2 Javascript

孤人 提交于 2019-12-12 04:59:26
问题 How can I use ViewChild in Angular 2 Javascript? I have referred angular.io docs and I have tried with the following code and it is not working. Can anyone help me? Thanks in advance. main.html <router-outlet></router-outlet> app.component.js (function (app) { app.AppComponent = ng.core .Component({ selector: 'my-app', templateUrl: 'app/views/main.html', directives: [ng.router.ROUTER_DIRECTIVES], //<----not loading components here viewProviders: [ng.http.HTTP_PROVIDERS], queries: {

angular 2 unexpected routing on Internet Explorer

久未见 提交于 2019-12-12 04:58:56
问题 My spring-boot/angular 2 app(hosted on embedded tomcat) works fine on Chrome,Safari,Opera and Edge. However on IE the app directly routes to PageNotFound component. Added shims for IE to index.html but still no luck. thank you in advance index.html <!doctype html> <html> <head> <meta charset="utf-8"> <title> </title> <base href="."> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="icon" type="image/x-icon" href="./res/images/favicon.ico"> <!-- Latest compiled

Angular 2 reload component based on activated route

核能气质少年 提交于 2019-12-12 04:34:36
问题 I have a component which I want to re use for different router links and to reload it with server data based on the link param. From what I've seen at the moment it is suggested to have your get inside an ng zone in order to trigger the re-render of the components and its children. I am also passing the object from the http request further down to child components. This is the component onInit code: ngOnInit(): void { this.route.params.forEach((params: Params) => { let id = +params['id'];

Auxiliary routes in Angular 2 remains in the url after navigating away

纵饮孤独 提交于 2019-12-12 04:28:41
问题 I'm trying to use auxiliary routes to show different content in a sidebar, depending on which route you're on. The problem is that the auxiliary route remains (both in URL and the content) after navigating away. The HTML: <router-outlet></router-outlet> <router-outlet name="sidebar"></router-outlet> The RouteConfig: @RouteConfig([ {path: '/', name: 'Home', component: Home, useAsDefault: true}, {path: '/leadslist', name: 'LeadsList', component: LeadsList}, {aux:'/sidebar', name: 'Sidebar',

How to navigate to a specific part of the page with the Angular 2 Router?

房东的猫 提交于 2019-12-12 04:25:53
问题 I'm trying to navigate to a particular element in my Angular 2 component. From the documentation I've read, it says to use fragment with the NavigationExtras object. I'm not sure how to do this when I want to navigate within the same page. Another part of the problem is the part of the page I want to navigate to is loaded through trough a *ngFor and creating div elements with the id I want to navigate to. I may be trying to navigate to that part of the page before it's loaded into the DOM. I

Request data once through parent component and make accessible to all child routes? (Angular2)

别来无恙 提交于 2019-12-12 04:13:38
问题 I have a parent component with two child routes. Each child route will need to use/access the same data retrieved from a GET request. I think it may be wasteful to query the server each time a child route is loaded, so I thought a good way of doing this would be to query the server once through the parent route and then sharing the data afterwards through a bi-directional service, which I'm trying to implement following the angular docs closely. However, neither of the child components are

Angular2 routing issues - Zone aware error No elements in sequence

懵懂的女人 提交于 2019-12-12 04:05:25
问题 I have searched quite a bit and couldn't find any answer that solved my problem. So I am posting this question. My issue is very similar to this question. Angular 2.0.1 Router EmptyError: no elements in sequence But I couldn't resolve it even by adding pathMatch: 'full',. I am getting an intermittent zonewaware error when try to navigate from a list table (navigates to detail view) below is my module. @NgModule({ imports: [ CommonModule, RouterModule.forChild([ { path: 'teams', component:

Event not working in dynamic html in angular2

放肆的年华 提交于 2019-12-12 03:58:21
问题 Want to append the dynamic generated html in a DOM, its appending successfully in a DOM but none of the function is working like click etc. ngOnInit() { this.sideBarData += '<li class="sidebar-toggler-wrapper hide" >' + '<div class="sidebar-toggler" > </div>' + '</li>' + '<li class="sidebar-search-wrapper"></li>'; this.sideBarData += '<li class="nav-item start">' + '<a class="nav-link home name" (click)="HomeButton(event)">' + '<i class="fa fa-home"></i>' + '<span class="title">Home</span>' +

Angular 2: How to use same child component with different data?

对着背影说爱祢 提交于 2019-12-12 03:55:40
问题 I have a header that has menu consist of categories which they are the same component but different query. The first call from parent to child is executed perfectly but if i navigateto another category from inside this child component i get error! I know this is something wrong with the link when i navigate inside this child which make [routerLink] updated instantly. Also if i navigate from category child component to login component which is separated component will give me the same error!