1

I would like to load a certain template based on a condition. The value of the condition is retrieved via an @Input(). How do I choose the value for the templateUrl key in the annotation based on this value?

Karma
  • 2,196
  • 1
  • 22
  • 30
  • 1
    I suppose there's a similar question: http://stackoverflow.com/questions/36071097/how-can-i-have-dynamic-templateurl-for-angular2-component – Zasypin N.V. Dec 26 '16 at 11:15

1 Answers1

1

You should avoid this and break it to 2 separated components. In that case, you can use ngSwitchCase and depending on value load the component you need for that case, or you can use the same component but add two html blocks with *ngIf and then you can show/hide whatever you need.

Igor Janković
  • 5,494
  • 6
  • 32
  • 46
  • Thanks for the tip! Could you please explain why should this be avoided? – Karma Dec 26 '16 at 12:22
  • Because, the point of the angular 2 is to separate all the things to the small components and avoid large components with the lot of if/else logic. – Igor Janković Dec 26 '16 at 12:50