2016-06-23 09:47:54 -07:00
|
|
|
/**
|
|
|
|
|
* @license
|
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
|
*/
|
|
|
|
|
|
2017-01-03 16:54:46 -08:00
|
|
|
import {InjectionToken} from '@angular/core';
|
2016-06-08 15:36:24 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* A bridge between a control and a native element.
|
|
|
|
|
*
|
|
|
|
|
* A `ControlValueAccessor` abstracts the operations of writing a new value to a
|
|
|
|
|
* DOM element representing an input control.
|
|
|
|
|
*
|
|
|
|
|
* Please see {@link DefaultValueAccessor} for more information.
|
|
|
|
|
*
|
2016-08-17 07:44:39 -07:00
|
|
|
* @stable
|
2016-06-08 15:36:24 -07:00
|
|
|
*/
|
|
|
|
|
export interface ControlValueAccessor {
|
|
|
|
|
/**
|
|
|
|
|
* Write a new value to the element.
|
|
|
|
|
*/
|
|
|
|
|
writeValue(obj: any): void;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the function to be called when the control receives a change event.
|
|
|
|
|
*/
|
|
|
|
|
registerOnChange(fn: any): void;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the function to be called when the control receives a touch event.
|
|
|
|
|
*/
|
|
|
|
|
registerOnTouched(fn: any): void;
|
2016-08-24 16:58:43 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This function is called when the control status changes to or from "DISABLED".
|
|
|
|
|
* Depending on the value, it will enable or disable the appropriate DOM element.
|
|
|
|
|
*
|
|
|
|
|
* @param isDisabled
|
|
|
|
|
*/
|
|
|
|
|
setDisabledState?(isDisabled: boolean): void;
|
2016-06-08 15:36:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Used to provide a {@link ControlValueAccessor} for form controls.
|
|
|
|
|
*
|
|
|
|
|
* See {@link DefaultValueAccessor} for how to implement one.
|
2016-08-17 07:44:39 -07:00
|
|
|
* @stable
|
2016-06-08 15:36:24 -07:00
|
|
|
*/
|
2017-01-03 16:54:46 -08:00
|
|
|
export const NG_VALUE_ACCESSOR = new InjectionToken<ControlValueAccessor>('NgValueAccessor');
|