I have a two-choice radio group that I want to get a selected value of and pass it as one of the parameters to navigate to. In my earlier semi-related question someone suggested this solution: Angular2 - Radio Button Binding but I've been trying and failing to use it:
search.component.html:
<form autocomplete="on" class="form-inline">
<input style="border-color: white; max-width: 300px" name="name" autofocus type="text" #name placeholder="Name..."
class="form-control">
<div class=" btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-toggle active">
<input type="radio" [(ngModel)]="realm" name="realm" [ng-value]="'Feronis'" autocomplete="off" checked> Feronis
</label>
<label class="btn btn-toggle">
<input type="radio" [(ngModel)]="realm" name="realm" [ng-value]="'Angrathar'" autocomplete="off"> Angrathar
</label>
</div>
<button (click)="onSearch(name.value,realm)" class="btn btn-search">
<span class="fa fa-search"></span></button>
I also tried with ngValue
and value
.
search.component.ts:
export class SearchComponent implements OnInit {
realm: string;
onSearch(nameIn: string, realmIn: string) {
console.log(this.realm); // undefined
let nameCase = nameIn.charAt(0).toUpperCase() +
nameIn.slice(1).toLowerCase();
let realmCase = realmIn.charAt(0).toUpperCase() + // realmIn also undefined
realmIn.slice(1).toLowerCase();
this.router.navigate(['/character', realmCase, nameCase])
}}
Can't bind to 'ngValue' since it isn't a known property of 'input'.
I also have imports for
import {FormsModule} from "@angular/forms";
in app.module.ts
and search.component.ts