I have an application in which I need to import a component in another one, and use the imported component template.
Is it possible to change an HTML tag in the parent template. For example:
I have a component "component-a", with this template:
<input type="text" class="form-control">
In component "component-b" template, I would like to add attributes to the input tag above. "component-b" template example:
<h3>Enter your name:</h3>
<component-a></component-a>
How to update the input tag? Thanks.
You can use an input variable in component-b @Input() modifyInput: boolean = false;
.
Now you can add attributes based on the boolean:
<input type="text" class="form-control" [attr.name]="modifyInput ? 'Modified' : 'unmodified'"/>
Yes. For an instance lets take the value
attribute of <input>
// component-a
@Component({
selector:'component-a',
template:'<input type="text" value={{inputData}} class="form-control">'
})
export class ComponentA{
@Input()
inputData:string;
}
// component-b
<component-a [inputData]="'hello'"></component-a>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.