admin管理员组文章数量:1023251
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
1 Answer
Reset to default 2You 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>
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
1 Answer
Reset to default 2You 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>
本文标签: javascriptHow to load conditionally templateUrl html file in Angular 5 componentStack Overflow
版权声明:本文标题:javascript - How to load conditionally templateUrl html file in Angular 5 component - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745592571a2157976.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论