Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is there a way to load templates dynamically in angular2? In angular1 I used ng-include to load different html template in the main controller view. I know that angular2 can only take 1 templateUrl and been googling ng-include in angular2 and can't find any reference.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
178 views
Welcome To Ask or Share your Answers For Others

1 Answer

Why do you need ng-include when you can make the html as a custom new component and use it wherever you need it, thanks to the selector tag.

Eg:

    @Component({
      selector: 'app-my-component',
      templateUrl: './my-component.component.html'
  })

So here, the my-component.component.html file can have the markup you want to include or show everywhere else. and the selector tag value <app-my-component></app-my-component> can be used throughout your application markup html files(you can think of it as your everyday html tags--but highly customized in nature and interpreted by the angular framework first aka custom tags but built using angular).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...