[英]Angular2 rc.5 and hashbang
In previous rc.4 release setting up hashbang #! 在之前的rc.4版本中设置了hashbang#! looked like this
看起来像这样
bootstrap(ApplicationComponent, [....
{provide: LocationStrategy, useClass: HashLocationStrategy},
{provide: APP_BASE_HREF, useValue: '!'}
]);
Now in rc.5 everything got changed a litte bit and I struggle to find a way to have same address containing #! 现在在rc.5中,一切都变得轻微了,我很难找到一种方法来获得包含#的相同地址!
Angular docs are quite clear about setting up routing but hashbang is somewhat skipped in tha description( https://angular.io/docs/ts/latest/guide/router.html ) . Angular docs非常清楚设置路由,但在描述中有些跳过了hashbang( https://angular.io/docs/ts/latest/guide/router.html )。 Setting up hash alone is done like so in rc.5 app.routing.ts
在rc.5 app.routing.ts中就像这样设置散列
export const routing = RouterModule.forRoot(appRoutes, { useHash: true });
however not sure how to additionally define "!" 但是不确定如何另外定义“!” in url in rc.5
在rc.5的url中
I am not sure how it should be applied and in what form. 我不确定它应该如何应用以及以何种形式应用。 Perhaps in boostrap:... inside @NgModule in app.module but so far I did not make it work.
也许在boostrap中:...在app.module中的@NgModule里面,但到目前为止我没有让它工作。 Please suggest.
请建议。
you can do it like this in app.module.ts
file by adding it in providers
array 你可以在
app.module.ts
文件中这样做,方法是在providers
数组中添加它
import {ReflectiveInjector} from '@angular/core';
import { Http, Response, Request, HTTP_PROVIDERS } from '@angular/http';
let injector = ReflectiveInjector.resolveAndCreate(HTTP_PROVIDERS);
let http = injector.get(Http);
let authService = new AuthService(new LocalStorage(), http);
@NgModule({
imports: [
BrowserModule,
FormsModule,
routing,
],
declarations: [
AppComponent,
MyComponent,
],
bootstrap: [
AppComponent
],
providers: [
{provide:AuthService,useValue:authService}, // over here
AdminAuthGuard,
UserAuthGuard
]
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.