Angular2自定义URL解析程序不覆盖默认URL解析程序

时间:2017-06-05 17:28:09

标签: angular2-template

我创建了以下类的示例自定义URLResolver,并在NgModule中将此自定义URL解析器注入提供程序。当templateUrl在组件中加载时,没有错误但是没有在浏览器中显示任何日志'Inside Resolve'。我想从CDN加载模板但是覆盖UrlResolver本身不起作用。能不能让我知道我在做什么错误?

从'@ angular / compiler'导入{UrlResolver};

export class CustomUrlResolver extends UrlResolver {
    resolve(baseUrl: string, url: string): string {
        console.log('Inside Resolve');
        let nUrl = super.resolve(baseUrl, url);
        let appUrl = nUrl;
        if (!(nUrl.indexOf("localhost") >= 0)) {
            appUrl = "." + appUrl;
        }
        return appUrl;
    }
}






@NgModule({
  declarations: [
    AppComponent,
    AboutComponent,
    RepoBrowserComponent,
    RepoListComponent,
    RepoDetailComponent,
    HomeComponent,
    ContactComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    ReactiveFormsModule,
    HttpModule,
    RouterModule.forRoot(rootRouterConfig, { useHash: true })
  ],
  providers: [
    GithubService,
    { provide: UrlResolver, useClass: CustomUrlResolver }
  ],
  bootstrap: [ AppComponent ]
})
export class AppModule {

}

0 个答案:

没有答案