-
Notifications
You must be signed in to change notification settings - Fork 2
/
component.js
74 lines (60 loc) · 1.32 KB
/
component.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import {BaseComponent} from '../util/base-component';
import {MDCFormField} from '@material/form-field';
/**
* @ngdoc component
* @name mdcFormField
* @module mdc.form-field
*
* @param {boolean} [alignEnd] - whether to align the form element after the label
*/
export class MDCFormFieldController extends BaseComponent {
static get name() {
return 'mdcFormField';
}
static get bindings() {
return {
alignEnd: '<?',
};
}
static get $inject() {
return ['$scope', '$element'];
}
constructor(...args) {
super(...args);
this.$element.addClass('mdc-form-field');
}
$onChanges(changesObj) {
if (changesObj.alignEnd) {
this.$element.toggleClass('mdc-form-field--align-end', Boolean(this.alignEnd));
}
}
$postLink() {
this.syncIdToLabel();
}
$onDestroy() {
if (this.mdc) {
this.mdc.destroy();
}
}
setChildCtrl(ctrl) {
if (this.mdc) {
this.mdc.destroy();
}
if (ctrl && ctrl.mdc) {
this.mdc = new MDCFormField(this.$element[0]);
this.mdc.input = ctrl.mdc;
}
}
setInputId(id) {
this.inputId = id;
this.syncIdToLabel();
}
syncIdToLabel() {
if (this.inputId) {
const label = this.$element.find('label');
if (label[0]) {
label[0].setAttribute('for', this.inputId);
}
}
}
}