每当用户单击图像时,都会在我的页面中。页面上的任何内容现在都应该显示在模式中。目前我已经在我的 Angular 代码中复制了相同的 html 两次。 有什么方法我们可以在页面中重用相同的 html 以及 Angular 中的模式吗?
最佳答案
您可以使用所需的模板 html 创建一个组件,并在页面和模式中使用它
您还可以使用ng-template
和ng-container
@Component({
selector: 'app-root',
template: `
<ng-template #estimateTemplate let-lessonsCounter="estimate">
<div> Approximately {{lessonsCounter}} lessons ...</div>
</ng-template>
<ng-container
*ngTemplateOutlet="estimateTemplate;context:ctx">
</ng-container>
`})
export class AppComponent {
totalEstimate = 10;
ctx = {estimate: this.totalEstimate};
}
*示例取自 here
关于html - Angular 模态 : How to reuse the same html in modal as well as in the page,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72284878/