Angular 2: how to get parameters from URL without using routing?

I am trying to get the url parameters in my component to search using the externsre service. I read that I can use angular2 routes and get parameters using RouteParams, but I don’t think I need it because the first page of my angular application is the Razor view.

I will try to explain better. My url looks like this:      http: //dev.local/listing/? City = melbourne

I load my root component as a razor with something like:

<house-list city = "@Request.Params["city"]"></house-list>

then on my root component i:

export class AppComponent implements OnInit {
    constructor(private _cityService: CityService) { }

    response: any;
    @Input() city: any;

    ngOnInit() {
        this.getHouses();
    }

    getHouses() {
        this.__cityService.getHousesByCity(this.city)
            .subscribe(data => this.response = data);

    }
}

So, I expected the "city" in my component to get the string passed from the razor, but it is undefined.

? ? , ?

+4
1

Angular . JavaScript?

, , Location , .

+3

All Articles