Home > Software engineering >  A custom angular two-state checkbox component issue
A custom angular two-state checkbox component issue

Time:01-23

I'm trying to create a custom checkbox component to replace an old-old NG Prime version that had been being used but wanted to make it leaner/cleaner with some added aria points and utilizing more of the checkbox attributes directly. The problem I'm running into though (I'm guessing) is with updating the value accessor / ngmodel and could use some guidance on what I'm apparently missing...

I thought what I had was simplistic enough but apparently not. The idea is that @Input() binary is set to true by default expecting ngModel to have a boolean to use but I don't get the value from ngModel when it's initialized. I need ngModel to communicate that to the component though when it's used standalone as like <app-checkbox [ngModel]="blah"></app-checkbox> but also have value_accessor working as expected if it's used in say a reactive angular form etc.

I also get a "NG0303: Can't bind to 'checked' since it isn't a known property of 'app-checkbox'" in my instance, but it's not on the stackblitz which I don't understand.

  •  Tags:  
  • Related