import {Directive, Host, Inject, OnChanges, OnDestroy, Optional, Self, SimpleChanges, SkipSelf, forwardRef} from '@angular/core'; import {EventEmitter, ObservableWrapper} from '../../facade/async'; import {Control} from '../model'; import {NG_ASYNC_VALIDATORS, NG_VALIDATORS} from '../validators'; import {ControlContainer} from './control_container'; import {ControlValueAccessor, NG_VALUE_ACCESSOR} from './control_value_accessor'; import {NgControl} from './ng_control'; import {composeAsyncValidators, composeValidators, controlPath, isPropertyUpdated, selectValueAccessor} from './shared'; import {AsyncValidatorFn, ValidatorFn} from './validators'; export const controlNameBinding: any = /*@ts2dart_const*/ /* @ts2dart_Provider */ { provide: NgControl, useExisting: forwardRef(() => NgControlName) }; /** * Creates and binds a control with a specified name to a DOM element. * * This directive can only be used as a child of {@link NgForm} or {@link NgFormModel}. * ### Example * * In this example, we create the login and password controls. * We can work with each control separately: check its validity, get its value, listen to its * changes. * * ``` * @Component({ * selector: "login-comp", * directives: [FORM_DIRECTIVES], * template: ` *
* `}) * class LoginComp { * onLogIn(value): void { * // value === {login: 'some login', password: 'some password'} * } * } * ``` * * We can also use ngModel to bind a domain model to the form. * * ``` * @Component({ * selector: "login-comp", * directives: [FORM_DIRECTIVES], * template: ` * * `}) * class LoginComp { * credentials: {login:string, password:string}; * * onLogIn(): void { * // this.credentials.login === "some login" * // this.credentials.password === "some password" * } * } * ``` * * @experimental */ @Directive({ selector: '[ngControl]', providers: [controlNameBinding], inputs: ['name: ngControl', 'model: ngModel'], outputs: ['update: ngModelChange'], exportAs: 'ngForm' }) export class NgControlName extends NgControl implements OnChanges, OnDestroy { /** @internal */ update = new EventEmitter(); model: any; viewModel: any; private _added = false; constructor(@Host() @SkipSelf() private _parent: ControlContainer, @Optional() @Self() @Inject(NG_VALIDATORS) private _validators: /* Array