Angular2: non-populating router parameters

So I'm losing my mind about it

I have a page with many components ... but for some reason I am having problems with one ...

it is intended to be searched in the main window of the page ... for debugging purposes, I split it to the minimum minimum and still does not work

This is my search component.

import { Component, OnInit }    from '@angular/core';

import { ROUTER_DIRECTIVES }    from '@angular/router';
import { Router, ActivatedRoute } from '@angular/router';


@Component({
    selector: 'main-search',
    template: `<div></div>`,
})

export class MainSearch implements OnInit {
    private sub: any;
    constructor(private route: ActivatedRoute){

    }

    ngOnInit(){

        this.sub = this.route.params.subscribe(params => {
            console.log('PARAMS FROM MAIN SEARCH', params);

        });
    }

}

as you can see i am trying to write parameters from url (fe http: // localhost: 8080 / indices; search = test )

NOT populated

I have a similar component with exact behavior (subscribing to params onInit ...

this.sub = this.route.params.subscribe(params => {
    console.log('PARAMS FROM INDICES: ', params);
})

And that one actually records the bloody parameters!

From the console:

PARAMS FROM MAIN SEARCH Object {} => main-search.ts?8502:24
Angular 2 is running in the development mode. Call enableProdMode() to enable the production mode.   => lang.js?c27c:360
null => index.service.ts?0bf5:40
FROM API => index.service.ts?0bf5:49
PARAMS FROM INDICES:  Object {search: "test"} => indicesList.component.ts?5ff1:63 

It is strange that only mainsearch is registered on the console before Angular2 disclaimer

, - ?

+4
1

, ActivatedRoute.

:

constuctor(
    private _activatedRoute: ActivatedRoute,
) {}

ngOnInit() 
    this._activatedRoute.params.subscribe(params => console.log(params));
}

, " " URL-. , ActivatedRoute .

-2

Source: https://habr.com/ru/post/1648644/


All Articles