angular2-routing

Angular 2 No provider for RouterOutletMap when lazy loading

岁酱吖の 提交于 2019-12-04 06:39:34
问题 I'm using the latest Angular CLI build (16) and I'm trying to lazy load routes but it fails for some reason, I can't find any new questions or solutions for this. Folder structure: core.component.html: <router-outlet></router-outlet> core.component.ts: import {NgModule} from '@angular/core'; import {BrowserModule} from '@angular/platform-browser'; import {RouterModule} from '@angular/router'; // Modules import {AdminAreaModule} from './+admin-area'; // Services import {GlobalsService,

Angular 2: Route parameter changes, reload the same page?

百般思念 提交于 2019-12-04 06:07:45
I have a route with a parameter, when going to the page /users/123 where 123 is the parameter the ngOnInit is called, I get my parameter and I call my method to get the user. However, when I'm on that page and I click a second link /users/456 then the ngOnInit is not called anymore (because that page is already instantiated). So without ngOnInit I can't get the route parameter and can't call my method to get the user. If I go to /users/123, then to /home, then to /users/456, it works obviously. What do I have to use to make sure the function that gets the parameter and gets the user is ALWAYS

Angular 2 get routeParams in a service

醉酒当歌 提交于 2019-12-04 06:05:40
I want to shift the logic from component to service. But I found out that I can't get the routeParams in a service. My component looks like import { Component, OnInit } from '@angular/core'; import { ActivatedRoute, Params } from '@angular/router'; import { MyService } from '../services/my.service'; @Component({ moduleId: module.id, templateUrl: 'my.component.html', styleUrls: ['my.component.css'] }) export class MyComponent implements OnInit { constructor(private myService: MyService, private route: ActivatedRoute) {;} public ngOnInit() { this.route.params .subscribe((params: Params) => {

router.navigate changes the URL, but is not rendering the component

懵懂的女人 提交于 2019-12-04 06:03:01
Instead of using <a href="/my-path/{{my_param}}"></a> in my template, I am willing to use a function with paramters to redirect me to a page. So, this is how I built my function in my .ts file: redirectToChat(my_param){ this.router.navigate(['./my-path/' + my_param ]); } And how I called it in my template: <div (click)="redirectToChat(my_param)"> ... </div> It changes the URL, but not rendering the component. I imported this in my component: import { Router, ActivatedRoute, ParamMap } from '@angular/router'; And I used it in my constructor: private router: Router Can you help me to render

How to preload angular2 views so will not flicker white page on first load?

荒凉一梦 提交于 2019-12-04 05:53:16
I am building an angular 2 app in plain JS. My problem is that when I change from a page to another it flicker a white page until the new view is rendered. This happens for all components only first time I access them. If I go to same route second time the page is loaded without white page. I capture the screen to explain better my problem: https://drive.google.com/file/d/0B5pOsXT-4rdTbmtuVnlUdXRMdE0/view?usp=sharing Here is my main view: <router-outlet></router-outlet> <nav id="menu"> <a [routerLink]="['Page1']">Page 1</a> <a [routerLink]="['Page2']">Page 2</a> <a [routerLink]="['Page3']"

Angular 2: How do I get params of a route from outside of a router-outlet

こ雲淡風輕ζ 提交于 2019-12-04 05:41:52
Similar question to Angular2 Get router params outside of router-outlet but targeting the release version of Angular 2 (so version 3.0.0 of the router). I have an app with a list of contacts and a router outlet to either display or edit the selected contact. I want to make sure the proper contact is selected at any point (including on page load), so I would like to be able to read the "id" param from the route whenever the route is changed. I can get my hands on routing events by subscribing to the router's events property, but the Event object just gives me access to the raw url, not a parsed

Angular 2 app base href with Cordova IOS

瘦欲@ 提交于 2019-12-04 05:26:47
I am developing an application using Angular 2 with cordova. I have used the angular cli to build the appplication. I have now ran into some routing issues on startup when it comes to the IOS application. The base href seems to be set wrong. If I set the base href using: <base href="/" target="_blank"> the application doesn't load. If the base href is set when I bootstrap the application using: ...,provide(APP_BASE_HREF, {useValue:'/'}), ... the application will load but I get the following exception: EXCEPTION: Error: Uncaught (in promise): Error: Cannot match any routes: 'var/containers

Angular 2, routerOnActivate method is never called for a component that implements OnActivate

我的梦境 提交于 2019-12-04 05:12:28
I am trying to log the current route using Angular 2 Router, using the sample code from the official documentation: https://angular.io/docs/ts/latest/api/router/OnActivate-interface.html import {Component} from 'angular2/core'; import { OnActivate, ComponentInstruction } from 'angular2/router'; @Component({selector: 'header-title', template: `<div>routerOnActivate: {{log}}</div>`}) export class HeaderTitle implements OnActivate { log: string = ''; routerOnActivate(next: ComponentInstruction, prev: ComponentInstruction) { console.log('hello on activate'); this.log = `Finished navigating from "$

Angular2 How to display error page while keeping route

你说的曾经没有我的故事 提交于 2019-12-04 04:57:17
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 re-navigate to the broken page to try again. Thanks! You can add this: setRouteErrorHandler(): void {

Angular 2 Router Using BehaviorSubject Observable in Resolve

左心房为你撑大大i 提交于 2019-12-04 04:56:43
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.subscribe((myData) => { console.log([myData, 'this console message DOES show up']); }); // if I return