0

I'm considering using non-Angular transport to load templates asynchronously (actually I would like to decide on build time if the template is a string or a promise coming from the request), like

@Component({
    directives: [],
    selector: 'some',
    template: System.import('./some-template!text')
})
export class SomeComponent {}

Can a promise (coming from request) be provided as component template?

Is there some kind of templateProvider functionality for directives/components?

Estus Flask
  • 206,104
  • 70
  • 425
  • 565
  • are you talking about relative path of `templateUrl` ? – Pardeep Jain May 07 '16 at 04:27
  • @PardeepJain I'm considering a replacement for templateUrl because I would like to decide if the template is loaded synchronously (with `require`) or asynchronously (with `System.import`) on build time. – Estus Flask May 07 '16 at 16:23

1 Answers1

1

Type of template is string, see source.

Alternatively you can use

templateUrl: 'relative/path/from/index.html/some-template.html'

I tried to do the impossible with IIFE and System.import with no luck.

You can try with IIFE and your own module loader to load templates synchronously. asynchronously I don't think would work.

See this, why you have to use IIFE.

Community
  • 1
  • 1
Ankit Singh
  • 24,525
  • 11
  • 66
  • 89
  • Thanks for the link to ComponentMetadataFactory, haven't found it by myself. As for IIFE, it shouldn't be here, because System.import returns a promise, not a function. – Estus Flask May 07 '16 at 16:31
  • You're welcome... I see, my bad, never used `System.import` before – Ankit Singh May 07 '16 at 16:50