1

Is there a way to load dynamic urls in templateUrl. Something like below code :-

@Component({
    moduleId: module.id,
    selector: 'my-app',
    templateUrl: DynamicUrl, //Load DynamicUrl here
    styleUrls: ['app.component.css']
})


export class AppComponent{

    var DynamicUrl= 'app.component.html';

     // ideally this template name will be pulled from the server.

}

I am confused about the lifecycle. Where to initialize and define the DynamicUrl and apply the logic to fetch from server.

Any kind of help is appreciated.

UzUmAkI_NaRuTo
  • 565
  • 3
  • 8
  • 20
  • This might help http://stackoverflow.com/questions/31692416/dynamic-template-urls-in-angular-2 – Priyesh Kumar Jun 10 '16 at 10:53
  • ya i came accross that before. but it involves @View decorator which was dropped in beta. hence i mentioned rc version. and it needs to create fake component. there must be some cleaner workaround. – UzUmAkI_NaRuTo Jun 10 '16 at 11:06

1 Answers1

0

Perhaps building a parent context object, used with a template string could work. templateUrl:`${foo}`,

const dynamicUrl = ():string => {
    //...do stuff

    return 'url-string'
}

@Component({
    //...
    templateUrl: `${dynamicURL()}`
})

//...
Rex
  • 376
  • 2
  • 11