如何监视和设置没有路由的url搜索参数?
“地点”而且似乎有我想要的。但是我得到这个错误:
错误:没有提供位置!
包括以下内容:

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){}
}

我怎么知道它想要哪个供应商?有没有更好的方法来实现这一点?

最佳答案

我做过一次。要实现HashLocationStrategy您必须像在主组件中那样实现它:

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 })]
);

10-05 20:51
查看更多