我正在尝试使用自定义组件包装 ng-select ( https://github.com/ng-select/ng-select ) 组件,我正在使用具有反应形式的 ControlValueAccessor,
export class ShNgSelectComponent implements OnInit, OnChanges,
ControlValueAccessor {
@Input() shItems: Array<object>;
@Input() shBindValue: string;
@Input() shBindLabel: string;
@Input() shPlaceholder: any;
@Output() shChange = new EventEmitter<Object>();
ngOnInit() {
}
writeValue(value: any): void {
this.shItems = value || '';
}
propagateChange(event){
this.shChange.emit(event);
}
registerOnChange(fn) {
this.propagateChange = fn;
}
registerOnTouched() { }
}
这是 sh-ng-select 的模板
<ng-select [items]='shItems' [bindValue]='shBindValue' [placeholder]='shPlaceholder' [bindLabel]='shBindLabel' (change)='propagateChange($event)'></ng-select>
这是我要嵌入自定义组件的主要组件
<sh-ng-select [shItems]='manufactureList' [shFormGroup]='requestForm' (shChange)='getModels($event)' formControlName="manufactureId" [shPlaceholder]='"اختر الشركة المصنعة"' [shBindValue]='"id"' [shBindLabel]='"name"'></sh-ng-select>
shChange 事件在我添加 formControlName 之前正常触发,但是一旦我这样做,事件就不会触发,并且控制台不会抛出任何错误......这是为什么呢?