Angular (4.x): Cannot use same name attribute for radio buttons -
i'm trying make radio buttons work, angular complains "name" attribute.
<form> <div> <h3>select building</h3> <h4>building search</h4> <label for="criteria">search criteria:</label> <input class="radio-input" type="radio" name="building-search-criteria" [(ngmodel)]="build_search_criteria" [value]="id" id="id"> <label class="radio-label" for="id">id</label> <input class="radio-input" type="radio" name="building-search-criteria" [(ngmodel)]="build_search_criteria" [value]="name" id="name"> <label class="radio-label" for="nombre">name</label> </div> </form>
in order make radio buttons work, have share samename
attribute, seemingly angular doesn't that:
if ngmodel used within form tag, either name attribute must set or form control must defined 'standalone' in ngmodeloptions. example 1: <input [(ngmodel)]="person.firstname" name="first"> example 2: <input [(ngmodel)]="person.firstname" [ngmodeloptions]="{standalone: true}">
build_search_criteria
is string variable. if understand, since bound model, value defined thevalue
attribute of chosen radio button.
how can make radio buttons work? thank you.
use value
instead of [value]
.as [value]
expects variable.and yeah, not giving ngmodel related error me , should not.
<form> <div> <h3>select building</h3> <h4>building search</h4> <label >search criteria:</label> <label class="radio-label" for="id">id</label> <input class="radio-input" type="radio" name="building-search-criteria" [(ngmodel)]="build_search_criteria" value="id" id="id"> <label class="radio-label" for="name">name</label> <input class="radio-input" type="radio" name="building-search-criteria" [(ngmodel)]="build_search_criteria" value="name" id="name"> </div> </form>
Comments
Post a Comment