4

Tried to modify soultion from here. It works fine, but if you change template to templateUrl in component, that should load dynamically, you get an error: "No ResourceLoader implementation has been provided. Can't read the url ...".

@Component({
    selector: 'string-editor',
    templateUrl: 'app/parts/string.html', //using template URL instead of inline template here
})
export class StringEditor { ... }

Live example on plunker. Any ideas how to fix this?

Community
  • 1
  • 1
Max
  • 43
  • 1
  • 4
  • 1
    Did you get anywhere with this? I'm facing the same issue. – Fergal Moran Sep 27 '16 at 19:51
  • You are probably using `COMPILER_PROVIDERS` which has a line: `{ provide: ResourceLoader, useValue: _NO_RESOURCE_LOADER }`. [Source](https://github.com/angular/angular/blob/master/modules/@angular/compiler/src/compiler.ts#L58) – cy3er Sep 29 '16 at 09:46
  • 1
    @FergalMoran see the answer below. – Max Sep 29 '16 at 13:00
  • @MAx : can you please share your code, which you have implemented? – Sandip - Frontend Developer Feb 13 '17 at 07:44
  • @SandipPatel it was the same as in accepted answer below. But it looks like in angular 2.4 Compiler was removed from exports. If you need dynamic component loading, take a look at this article https://angular.io/docs/ts/latest/cookbook/dynamic-component-loader.html – Max Feb 14 '17 at 10:14

1 Answers1

3

Don't use COMPILER_PROVIDERS, because it overrides the ResourceLoader.

For dynamic loading use the Compiler from core package (which is actually the same as RuntimeCompiler):

@Inject(Compiler) protected compiler: Compiler

and add the ApplicationModule as import in your module:

imports: [ 
    ApplicationModule,
    BrowserModule,
    DynamicModule.forRoot() // singletons
],

Plunker

cy3er
  • 1,699
  • 11
  • 14