我参考了角度素材2的自动完成源代码,可以找到here。
MdAutocompleteTrigger
实施ControlValueAccessor
。以下是writeValue
方法的实现:
/**
* Sets the autocomplete's value. Part of the ControlValueAccessor interface
* required to integrate with Angular's core forms API.
*
* @param value New value to be written to the model.
*/
writeValue(value: any): void {
Promise.resolve(null).then(() => this._setTriggerValue(value));
}
有人可以解释一下在这里使用Promise的必要性吗?