在 Angular 中使用外部库中的 templateUrl

问题描述 投票:0回答:1

在我的 Angular 15 应用程序中,通过引用 TemplateUrl 中的相同模板文件,我有许多使用相同模板的组件。

例如:

@Component({
  selector: 'app-my-comp',
  templateUrl:'../../myTemplate.html',// this is a common template,
})
export class MyComponent {
}

出于某种原因,我需要获取应用程序的

myTemplate.html
,并将其设置在我的项目的外部库中。

现在我被困住了。

我不知道怎么做

1.从库导出 html 模板(在库的公共 api 中我只能导出 ts 文件)。

2.在

MyComponent
组件的 TemplateUrl 中使用它。

提前致谢!

angular angular-template angular-library
1个回答
0
投票

也许我错了,但我认为这是不可能的。 在多个组件中使用相同的模板也是要谨慎使用的。

也许您应该解释一下您的用例,然后我们可以寻找不同的解决方案/架构。

例如,如果您需要相同的模板但不同的功能,您应该将 UI 移至所谓的“哑组件”中,并在多个智能组件中重复使用它。

© www.soinside.com 2019 - 2024. All rights reserved.