How to load conditionally templateUrl html file in Angular 5 component

前端 未结 2 1758
一个人的身影
一个人的身影 2021-02-09 00:31

There is one scenario in my project, Consider, I have one testDynamic component

@Component({
    templateUrl: \"./test-dynamic.html\", // Need to override this f         


        
相关标签:
2条回答
  • 2021-02-09 01:16

    You can't add more than one HTML file.

    What you can do is, use *ngIf or *ngSwitchCase to show only parts of the template if that is your intention. Then you have only one template html file.

    Then html of your template will be something like this:

    <div *ngIf="YOUR_CONDITION">View 01</div>
    <div *ngIf="YOUR_CONDITION">View 02</div>
    
    0 讨论(0)
  • 2021-02-09 01:28

    refer the following link, this is a good example of dynamic templateUrl

    Angular 2/4 component with dynamic template or templateUrl

    0 讨论(0)
提交回复
热议问题