当我尝试添加hashlocationstrategy时发生此错误
boot.ts
///<reference path="../typings/browser.d.ts"/>
import { bootstrap } from "angular2/platform/browser";
import { RootComponent } from "./root.component";
import { ROUTER_PROVIDERS, ROUTER_DIRECTIVES, LocationStrategy, HashLocationStrategy} from "angular2/router";
import { PLATFORM_DIRECTIVES, provide, enableProdMode } from "angular2/core";
import { HTTP_PROVIDERS } from "angular2/http";
import { FirebaseService } from "./shared/firebase.service";
import { Environment } from "./config/environment";
if (Environment === "production") {
enableProdMode();
}
bootstrap(RootComponent, [
FirebaseService,
ROUTER_PROVIDERS,
HTTP_PROVIDERS,
provide(
[PLATFORM_DIRECTIVES, {useValue: [ROUTER_DIRECTIVES], multi: true}],
[LocationStrategy, {useClass: HashLocationStrategy}]
)
])
.catch(err => console.error(err));
认为它是因为我使用平台指令和locationstrategy这样的语法是错误的。有线索吗?
答案 0 :(得分:1)
provide()
和PLATFORM_DIRECTIVES
LocationStrategy
bootstrap(RootComponent, [
FirebaseService,
ROUTER_PROVIDERS,
HTTP_PROVIDERS,
provide(PLATFORM_DIRECTIVES, {useValue: ROUTER_DIRECTIVES, multi: true}),
provide(LocationStrategy, {useClass: HashLocationStrategy})
.catch(err => console.error(err));
答案 1 :(得分:0)
您可以尝试以这种方式引导您的应用程序:
bootstrap(RootComponent, [
FirebaseService,
ROUTER_PROVIDERS,
HTTP_PROVIDERS,
provide(
PLATFORM_DIRECTIVES, {useValue: [ROUTER_DIRECTIVES], multi: true}),
provide(LocationStrategy, {useClass: HashLocationStrategy})
])
.catch(err => console.error(err));
请参阅此plunkr:https://plnkr.co/edit/6fXmPi?p=preview