Issue
Is it possible to get values of a form by formControlName, in a non input tag?
<label>Name</label>
<input type="text" formControlName="name"/>
But what I need is something like this (a tag is just an example of a non input tag):
<div>
<label>Name</label>
<a (click)="someFunction()" formControlName="name"/>
</div>
Is it possible in angular?
Solution
A FormGroup exist in the .ts. It's not necessary to have an input.
Really I don't know what do you want . To get a value of a FormControl you can use your_form.get('name_of_formControl').value
, e.g.
<div>
<label>Name</label>
<a (click)="someFunction()">{{form.get('name').value}}</a>
</div>
Or, e.g. you can change the value
<div>
<label>Name</label>
<a (click)="form.get('name').setValue('clicked')"/>
</div>
Or use a @if
<div>
<label>Name</label>
@if (!form.get('name').value){
<a> I'm not name</a>
}
</div>
Answered By - Eliseo
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.