I'm debugging my component that use ng-select and each time I'm typing into input my ngModel is changing even that I don't use ngModel in my view. I've removed every use of ngModel only class properties remained.
<div>
<div class="invlisible" #list>
<div *ngFor="let item of items">{{item}}</div>
</div>
<div class="invlisible" #value>{{ngModel}}</div>
<ng-select [items]="items"
[clearable]="false"
[loading]="loading"
[placeholder]="placeholder"
[typeahead]="typeahead">
</ng-select>
</div>
When I've put "x" into ng-select input my ngModel is changing, I've removed every use of ngModel only this is in my component:
@Component({
selector: 'disco-ng-select',
templateUrl: './disco-ng-select.component.html',
styleUrls: ['./disco-ng-select.component.scss']
})
export class DiscoNgSelectComponent extends CSSProps implements OnInit, OnDestroy {
private _value: any;
@Input() public items: any[];
@Input() public loading: boolean;
@Input() public placeholder: string;
@Input() public typeahead: Observable<any[]>;
@Input() public ngModel: any;
@Output() public ngModelChange = new EventEmitter<any>();
constructor(
_host: ElementRef) {
super(_host);
}
public onChange(value: any) {
this.ngModelChange.emit(value);
}
}
ngModel is not connected in any way to my component but it's value is changing when I'm typing. The same is happening when I'm putting empty input, and enter text to that input, ngModel is changing.
How can I make ngModel (I want to use ngModel not [model]="value"
) work the same as normal two way data binding?
NG_VALUE_ACCESSOR
provider and implement theControlValueAccessor
interface, as shown in this answer. – ConnorsFanNG_VALUE_ACCESSOR
code + interface and empty methods disabled default behavior. If you want you can add answer it will be easier to find. – jcubic