How do I monitor and set URL search params without routing?
'Location' and seems to have what I want. However I get this error:
Error: No provider for Location!
With the following:
import { Component } from '@angular/core';
import { Location, HashLocationStrategy } from "@angular/common";
@Component({
selector: 'app-root',
templateUrl: 'app.component.html',
styleUrls: ['app.component.css'],
providers: [HashLocationStrategy]
})
export class AppComponent {
constructor(private location: Location){}
}
How do I know which provider it wants? And is there a better way to accomplish this?
I did it once. To implement HashLocationStrategy you will have to implements it like that in your MainComponent:
import {bootstrap} from '@angular/platform-browser-dynamic';
import {
Location,
LocationStrategy,
HashLocationStrategy,
APP_BASE_HREF
} from '@angular/common';
import {provide} from '@angular/core';
import {ROUTER_PROVIDERS} from '@angular/router-deprecated'
import { HTTP_PROVIDERS } from '@angular/http';
import {AppComponent} from './app.component';
bootstrap(
AppComponent
, [
HTTP_PROVIDERS
,ROUTER_PROVIDERS
, provide(APP_BASE_HREF, { useValue: '/' })
, provide(LocationStrategy, { useClass: HashLocationStrategy })]
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With