无法绑定到“routerLink”'因为它不是一个已知的本地财产

时间:2016-03-15 12:09:16

标签: javascript typescript angular angular2-routing

当我尝试添加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这样的语法是错误的。有线索吗?

2 个答案:

答案 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