角度6:如何将html文件包含到组件中? [英] Angular 6: How to include html file into component?
问题描述
在servlet环境中,我们可以包含以下任何jsp
:
In a servlet environment we can include any jsp
like this :
<%@include file=" 'path-to-jsp' " %>
在我的有角项目中,我有一个HTML表单,其中包含许多组件. 我想将此表单包含在两个组件中(创建和更新).
In my angular project I have a html form with many components in it. I want to include this form in 2 components (create and update).
user-form.html:
user-form.html :
<input type=".."...>
<input type=".."...>
<input type=".."...>
<select>...
create-user.component.html:
create-user.component.html:
<form>
// insert content of 'user-form.html' at compile time
<button>Create User</button>
</form>
update-user.component.html:
update-user.component.html:
<form>
// insert content of 'user-form.html' at compile time
<button>Update User</button>
</form>
在Angular 2+中有实现此目的的方法吗?
Is there a way of accomplishing this in Angular 2+ ?
注意:我使用反应形式
推荐答案
您可以将此用户表单作为模板添加到视图中.这样绑定也将起作用 像下面的例子一样
You can add this user-form as a template in your view. in this way binding will also work Like the following example
<user-form [state] = 'Create/Update'></user-form>
<button>Create/Update</button>
,用户组件将状态作为输入来检查它是否处于编辑或创建状态. 并在UserFormComponent中将选择器称为用户窗体",并在当前组件中包括UserFormComponent.
and the user component will take the state as an input to check whether it's in edit or create state. And mention the selector as "user-form" in the UserFormComponent and also include UserFormComponent in your current component.
这篇关于角度6:如何将html文件包含到组件中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!