我遇到了一些Angular代码问题。这是一个基础设施多选框,并且具有保存bttn,该保存bttn调用一个函数以使用键更新数组。由于某些原因,它总是发送多选框中的所有值,而不是仅发送选定的值。
这是我的组件代码
_contactId: string;
@Input() set contactId(contactId: string) {
this._contactId = contactId;
};
get contactId() {
return this._contactId;
}
_allBuckets: IServerDropdownOption[];
@Input() set allBuckets(allBuckets: IServerDropdownOption[]) {
this._allBuckets = [...allBuckets];
};
get allBuckets() {
return this._allBuckets;
}
_selectedBuckets: Array<string>;
@Input() set selectedBuckets(selectedBuckets: Array<string>) {
this._selectedBuckets = selectedBuckets;
};
get selectedBuckets() {
return this._selectedBuckets;
}
@ViewChild('chipsSelect', { read: ChipsSelectComponent })
public chipsSelect: ChipsSelectComponent;
alive = true;
constructor(private contactsService: ContactsService) { }
ngOnInit() {
}
ngAfterViewInit() {
this.chipsSelect.multiSelectBox.onSave
.pipe(
takeWhile(_ => this.alive),
switchMap(updatedSelection => this.contactsService.updateBuckets(this.contactId, updatedSelection.map(tag => tag.value)))
)
.subscribe();
console.log('Selected Buckets: ' + this.selectedBuckets)
}
ngOnDestroy(): void {
this.alive = false;
}
}
所以我有2个问题,谁能告诉我我做错了什么以保存所有选定项,以及如何将所有选定项打印到用户单击保存的控制台中。我当前的console.log仅在init上打印,而在保存时不打印。