我想在角度路线中使用哈希。我试图找到,但所有的例子都是最老的版本。任何建议我怎么能这样做?
我试过了:
let injector = ReflectiveInjector.resolveAndCreate(NgModule);
let http = injector.get(Http);
let authService = new AuthService(new LocalStorage(), http);
providers: [ {provide:AuthService,useValue:authService}, // over here
SharedService,DatePipe],
但我得到错误:
找不到本地存储,找不到AuthService而且我无法使用 ReflectiveIncjector中的NgModule。
任何建议我如何使用hashbang?
答案 0 :(得分:7)
在@NgModule
中使用useHash:true
:
imports: [
RouterModule.forRoot([
...
]
,{ useHash: true }
)],
来源:https://angular.io/docs/ts/latest/guide/router.html#!#-hashlocationstrategy-