简体   繁体   English

重用角度组件(但修改Dom元素)

[英]Reusing an Angular Component (but modifying the Dom Elements)

So, I created an Angular component, which I want to reuse within some of my pages that I will be creating. 因此,我创建了一个Angular组件,希望在将要创建的某些页面中重用它。 Essentially, it is a form box with different configurations (input fields, buttons, check boxes, etc.). 本质上,它是具有不同配置(输入字段,按钮,复选框等)的表单框。 Based on certain section, I want to change the content of the form box, however, I still want to keep the same layout of the form. 基于某些部分,我想更改表单框的内容,但是,我仍然想保持表单的相同布局。 So, for example, I want to apply the same css properties of the form and of the form relative to the whole page. 因此,例如,我想对表单和相对于整个页面应用相同的CSS属性。

For certain pages of the application I am building, I reuse the same form 3 or 4 times, however, I change the content of what is in each instance of the form. 对于正在构建的应用程序的某些页面,我重复使用了3到4次相同的表单,但是,我更改了表单每个实例中内容的内容。 I want to be able to call the selector( ), but I want to be able to change the content of what is in that selector. 我希望能够调用选择器(),但是我希望能够更改该选择器中内容的内容。 This way it will make creating the application much faster. 这样,它将使创建应用程序更快。

The content of the forms (like the input fields and buttons) are placed in different components. 表单的内容(如输入字段和按钮)放置在不同的组件中。 I want to insert a specific content component within the one instance of the form component. 我想在表单组件的一个实例中插入一个特定的内容组件。 Then insert another content component within another instance of a form component. 然后,将另一个内容组件插入到表单组件的另一个实例中。

Any easy way of doing this ? 有任何简单的方法吗? Any help or guidance would be appreciated. 任何帮助或指导,将不胜感激。

This picture is a mock-up of what ideally I want a page to look like. 这张图片是理想情况下我想要页面外观的模型。 The first form has somewhat different content, but essentially the same component with some adjustments. 第一种形式的内容有些不同,但是基本相同,但进行了一些调整。

I feel like what you're trying to do could get messy quickly, but you could use inputs to change the behaviour of the form. 我觉得您尝试做的事情可能很快就会变得混乱,但是您可以使用输入来更改表单的行为。

For example, if you wanted to hide or show a textbox in the form, you could have 例如,如果您想隐藏或显示表单中的文本框,则可以

<input type="text" *ngIf="showTextbox" /> 

in your html and 在你的HTML和

@Input() showTextbox : boolean = true; // Defaulted to true

and then specify whether you want the textbox each time you use the component. 然后指定每次使用组件时是否要使用文本框。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM