javascript - How to load conditionally templateUrl html file in Angular 5 component - Stack Overflow

There is one scenario in my project,Consider, I have one testDynamic ponent@Component({templateUrl: &q

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

@Component({
    templateUrl: "./test-dynamic.html", // Need to override this file
    styleUrls: ['./test-dynamic.css']
})
export class testDynamic {
    constructor() { }
}

here need to check if an override1.html file is exists in override folder then load this file as templateUrl otherwise load the ponent default test-dynamic.html. Any idea how to achieve this.?

refer the following image for clearly understanding

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

@Component({
    templateUrl: "./test-dynamic.html", // Need to override this file
    styleUrls: ['./test-dynamic.css']
})
export class testDynamic {
    constructor() { }
}

here need to check if an override1.html file is exists in override folder then load this file as templateUrl otherwise load the ponent default test-dynamic.html. Any idea how to achieve this.?

refer the following image for clearly understanding

Share Improve this question asked Apr 23, 2018 at 6:35 ranjit redekarranjit redekar 9471 gold badge12 silver badges25 bronze badges 3
  • 2 You will check the below: <br> stackoverflow./questions/31692416/… – GSK Commented Apr 23, 2018 at 6:48
  • 1 @GSK Thanks, I read you shared link and tried on localhost but almost all solutions are not working with Angular 5. – ranjit redekar Commented Apr 23, 2018 at 10:04
  • Refer this link stackoverflow./questions/45376628/… – ranjit redekar Commented May 3, 2018 at 9:00
Add a ment  | 

1 Answer 1

Reset to default 2

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>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745592573a4634921.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信