Skip to content

Commit 226740a

Browse files
committed
started md-input directive
1 parent 810e4e4 commit 226740a

File tree

1 file changed

+46
-1
lines changed

1 file changed

+46
-1
lines changed

src/lib/input/input-wrapper.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
ElementRef,
1010
QueryList,
1111
OnChanges,
12-
ViewEncapsulation
12+
ViewEncapsulation, HostListener, HostBinding, Optional
1313
} from '@angular/core';
1414
import {MdError, coerceBooleanProperty} from '../core';
1515
import {NgModel} from '@angular/forms';
@@ -73,6 +73,51 @@ export class MdHint {
7373
@Input() align: 'start' | 'end' = 'start';
7474
}
7575

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+
76121

77122
/**
78123
* Component that represents a text input. It encapsulates the <input> HTMLElement and

0 commit comments

Comments
 (0)