|
9 | 9 | ElementRef, |
10 | 10 | QueryList, |
11 | 11 | OnChanges, |
12 | | - ViewEncapsulation |
| 12 | + ViewEncapsulation, HostListener, HostBinding, Optional |
13 | 13 | } from '@angular/core'; |
14 | 14 | import {MdError, coerceBooleanProperty} from '../core'; |
15 | 15 | import {NgModel} from '@angular/forms'; |
@@ -73,6 +73,51 @@ export class MdHint { |
73 | 73 | @Input() align: 'start' | 'end' = 'start'; |
74 | 74 | } |
75 | 75 |
|
| 76 | +@Directive({ |
| 77 | + selector: '[md-input]' |
| 78 | +}) |
| 79 | +export class MdInputDirective implements AfterContentInit { |
| 80 | + @Input() disabled = false; |
| 81 | + |
| 82 | + @Input() @HostBinding() |
| 83 | + get id() { return this._id; }; |
| 84 | + set id(value: string) { this._id = value || this._uid; } |
| 85 | + private _id: string; |
| 86 | + |
| 87 | + @Input() required = false; |
| 88 | + |
| 89 | + @Input() type = 'text'; |
| 90 | + |
| 91 | + @HostListener('focus') private _onFocus() { |
| 92 | + this.focused = true; |
| 93 | + } |
| 94 | + |
| 95 | + @HostListener('blur') private _onBlur() { |
| 96 | + this.focused = false; |
| 97 | + } |
| 98 | + |
| 99 | + focused = false; |
| 100 | + |
| 101 | + private get _uid() { |
| 102 | + return this._existingUid = this._existingUid || `md-input-${nextUniqueId++}`; |
| 103 | + } |
| 104 | + private _existingUid: string; |
| 105 | + |
| 106 | + constructor(@Optional() private _ngModel : NgModel) { |
| 107 | + // Force setter to be called in case id is not set. |
| 108 | + this.id = this.id; |
| 109 | + } |
| 110 | + |
| 111 | + ngAfterContentInit() { |
| 112 | + console.log('disabled', this.disabled); |
| 113 | + console.log('id', this.id); |
| 114 | + console.log('required', this.required); |
| 115 | + console.log('type', this.type); |
| 116 | + console.log('focused', this.focused); |
| 117 | + console.log('ngModel', this._ngModel); |
| 118 | + } |
| 119 | +} |
| 120 | + |
76 | 121 |
|
77 | 122 | /** |
78 | 123 | * Component that represents a text input. It encapsulates the <input> HTMLElement and |
|
0 commit comments