export class CheckboxComponent {
formControl: FormControl;
option: {value: string};
constructor() {
this.formControl = new FormControl();
this.option = {value: "MyValue"};
this.formControl.valueChanges.subscribe(console.log);
}
}
<input type="checkbox" [formControl]="formControl" [value]="option.value" name="SomeName" />
구독의 출력은 참, 거, 참, 거짓 .... I입니다 각도 2가 FormControl의 "MyValue"문자열 값을 바인딩하게하십시오.
기본적으로 각도 2, FormControl 및 체크 상자는 기본 브라우저 제출 동작이 확인란의 값을 보내고 동일한 이름을 가진 여러 확인란의 경우 확인란의 배열이므로 이상한 부울 값을 바인딩하는 것으로 보입니다 값은 체크 박스의 이름에 바인딩됩니다.
Items=[true, false, true, true, true, false]
대신에 :
이Items=[Toothbrush, Floss, Glock, Clean underwear]
그래서 본질적으로 어떻게 각 2 바인딩 문자열 값이 아닌 부울 값을 만드는
제출 꽤 쓸모가있을 것인가?
종류와 관련,
업데이트가 있습니까? 나는 똑같은 문제로 어려움을 겪고있다. –