1

I have created sample Custom URLResolver with following class and Injected this Custom URL Resolver in NgModule as provider. No errors but not showing up any log 'Inside Resolve' in the browser when templateUrl is loading in the component.I would like to load template from CDN but overriding UrlResolver itself is not working. Could you please let me know what is the mistake I am doing ?

import { UrlResolver } from '@angular/compiler';

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 {

}
Murali
  • 11
  • 2
  • Possible duplicate of [Angular UrlResolver is not overridden by custom provider](https://stackoverflow.com/questions/46566366/angular-urlresolver-is-not-overridden-by-custom-provider) – George Harris Oct 05 '17 at 08:33

0 Answers0