Angular 4 checkbox change value

2019-04-04 10:26发布

how could you achieve in Angular 4 that when you register in a checkbox save an "A" or "B" value. As much as I try, he is only sending me true or false, I hope someone can help me.

registry.component.ts

  this.userForm = new FormGroup({
   state: new FormControl('',),

  });

registry.component.html

<div class="form-group">
                <label>State</label>
          <input type="checkbox" [(ngModel)]="isChecked" (change)="checkValue(isChecked?'A':'B')" formControlName="state"/>
        </div>  

            <pre>{{userForm.value | json}}</pre>

That way I can get the console to show the value I want (A or B) but in the JSON is still true or false.

7条回答
一夜七次
2楼-- · 2019-04-04 10:55
<input type="checkbox" value="a" (click)="clicked('A')">A
<input type="checkbox" value="b" (click)="clicked('B')">B

clicked(val){
   console.log(val);
}

do want something like that?

查看更多
登录 后发表回答