diff --git a/modules/angular2/src/forms/directives.ts b/modules/angular2/src/forms/directives.ts index 6f6c8d6639..35215004f6 100644 --- a/modules/angular2/src/forms/directives.ts +++ b/modules/angular2/src/forms/directives.ts @@ -1,279 +1,23 @@ -import {Directive, Ancestor} from 'angular2/src/core/annotations/decorators'; -import {Optional} from 'angular2/src/di/decorators'; -import {ElementRef} from 'angular2/src/core/compiler/element_ref'; -import {Renderer} from 'angular2/src/render/api'; -import { - isPresent, - isString, - CONST_EXPR, - isBlank, - BaseException, - Type -} from 'angular2/src/facade/lang'; -import {ListWrapper} from 'angular2/src/facade/collection'; -import {ControlGroup, Control, isControl} from './model'; -import {Validators} from './validators'; +import {Type, CONST_EXPR} from 'angular2/src/facade/lang'; +import {ControlNameDirective} from './directives/control_name_directive'; +import {FormControlDirective} from './directives/form_control_directive'; +import {ControlGroupDirective} from './directives/control_group_directive'; +import {FormModelDirective} from './directives/form_model_directive'; +import {TemplateDrivenFormDirective} from './directives/template_driven_form_directive'; +import {DefaultValueAccessor} from './directives/default_value_accessor'; +import {CheckboxControlValueAccessor} from './directives/checkbox_value_accessor'; +import {SelectControlValueAccessor} from './directives/select_control_value_accessor'; -function _lookupControl(groupDirective: ControlGroupDirective, controlOrName: any): any { - if (isControl(controlOrName)) { - return controlOrName; - } - - if (isBlank(groupDirective)) { - throw new BaseException(`No control group found for "${controlOrName}"`); - } - - var control = groupDirective.findControl(controlOrName); - - if (isBlank(control)) { - throw new BaseException(`Cannot find control "${controlOrName}"`); - } - - return control; -} - -/** - * Binds a control group to a DOM element. - * - * # Example - * - * In this example, we bind the control group to the form element, and we bind the login and - * password controls to the - * login and password elements. - * - * Here we use {@link formDirectives}, rather than importing each form directive individually, e.g. - * `ControlDirective`, `ControlGroupDirective`. This is just a shorthand for the same end result. - * - * ``` - * @Component({selector: "login-comp"}) - * @View({ - * directives: [formDirectives], - * inline: "
" - * }) - * class LoginComp { - * loginForm:ControlGroup; - * - * constructor() { - * this.loginForm = new ControlGroup({ - * login: new Control(""), - * password: new Control("") - * }); - * } - * - * onLogin() { - * // this.loginForm.value - * } - * } - * - * ``` - * - * @exportedAs angular2/forms - */ -@Directive({selector: '[control-group]', properties: ['controlOrName: control-group']}) -export class ControlGroupDirective { - _groupDirective: ControlGroupDirective; - _directives: List