Skip to content

Commit be75575

Browse files
committed
style: fix form ts errors
1 parent 4f83cab commit be75575

File tree

5 files changed

+53
-75
lines changed

5 files changed

+53
-75
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,63 @@
11
import { AfterContentInit, Component, ContentChild, Input, OnDestroy } from '@angular/core';
2+
import { NgControl } from '@angular/forms';
23

3-
import { removeSubscriptions } from '../../helpers';
4+
import { Subscription } from 'rxjs';
45

6+
import { removeSubscriptions } from '../../helpers';
57
import {
68
InputGroupAddonLeftDirective,
79
InputGroupAddonRightDirective,
810
InputGroupContentDirective,
911
InputGroupLabelDirective
1012
} from './input-group.directive';
11-
1213
import { InputTextDirective } from '../input-text/input-text.directive';
13-
import { NgControl } from '@angular/forms';
14-
import { Subscription } from 'rxjs';
1514

1615

17-
/*
18-
*
19-
*/
2016
@Component({
2117
selector: 'mk-input-group',
2218
templateUrl: './input-group.component.html'
2319
})
2420
export class InputGroupComponent implements AfterContentInit, OnDestroy {
25-
private subscriptions: Array<Subscription> = [];
26-
27-
public currentColor: string;
28-
public currentFontColor: string;
29-
30-
@Input() addonLeft: string;
31-
@Input() addonRight: string;
21+
@Input() addonLeft?: string;
22+
@Input() addonRight?: string;
3223
@Input() inputColor = 'default';
33-
@Input() inputFontColor: string;
24+
@Input() inputFontColor?: string;
3425
@Input() inputErrorColor = 'danger';
35-
@Input() inputErrorFontColor: string;
26+
@Input() inputErrorFontColor?: string;
3627
@Input() inputValidColor = 'success';
37-
@Input() inputValidFontColor: string;
38-
@Input() label: string;
28+
@Input() inputValidFontColor?: string;
29+
@Input() label?: string;
3930
@Input() wrapperClasses = 'form-group';
4031

41-
@ContentChild(InputGroupLabelDirective) public inputGroupLabelDirective: InputGroupLabelDirective;
42-
@ContentChild(InputGroupAddonLeftDirective) public inputGroupAddonLeftDirective: InputGroupAddonLeftDirective;
43-
@ContentChild(InputGroupAddonRightDirective) public inputGroupAddonRightDirective: InputGroupAddonRightDirective;
44-
@ContentChild(InputGroupContentDirective) public inputGroupContentDirective: InputGroupContentDirective;
45-
@ContentChild(InputTextDirective) public inputTextDirective: InputTextDirective;
46-
47-
ngAfterContentInit() {
48-
this.subscriptions.push(this.inputTextDirective.onKeyup.subscribe((value: NgControl) => {
49-
if (value.invalid) {
50-
this.currentColor = this.inputErrorColor;
51-
this.currentFontColor = this.inputErrorFontColor;
52-
} else if (!value.invalid) {
53-
this.currentColor = this.inputValidColor;
54-
this.currentFontColor = this.inputValidFontColor;
55-
} else {
56-
this.currentColor = this.inputColor;
57-
this.currentFontColor = this.inputFontColor;
58-
}
59-
}));
32+
@ContentChild(InputGroupLabelDirective) public inputGroupLabelDirective?: InputGroupLabelDirective;
33+
@ContentChild(InputGroupAddonLeftDirective) public inputGroupAddonLeftDirective?: InputGroupAddonLeftDirective;
34+
@ContentChild(InputGroupAddonRightDirective) public inputGroupAddonRightDirective?: InputGroupAddonRightDirective;
35+
@ContentChild(InputGroupContentDirective) public inputGroupContentDirective?: InputGroupContentDirective;
36+
@ContentChild(InputTextDirective) public inputTextDirective?: InputTextDirective;
37+
38+
private subscriptions: Subscription[] = [];
39+
40+
public currentColor?: string;
41+
public currentFontColor?: string;
42+
43+
ngAfterContentInit(): void {
44+
if (this.inputTextDirective) {
45+
this.subscriptions.push(this.inputTextDirective.onKeyup.subscribe((value: NgControl) => {
46+
if (value.invalid) {
47+
this.currentColor = this.inputErrorColor;
48+
this.currentFontColor = this.inputErrorFontColor;
49+
} else if (!value.invalid) {
50+
this.currentColor = this.inputValidColor;
51+
this.currentFontColor = this.inputValidFontColor;
52+
} else {
53+
this.currentColor = this.inputColor;
54+
this.currentFontColor = this.inputFontColor;
55+
}
56+
}));
57+
}
6058
}
6159

62-
ngOnDestroy() {
60+
ngOnDestroy(): void {
6361
removeSubscriptions(this.subscriptions);
6462
}
6563
}

library/angular-admin-lte/src/lib/form/input-group/input-group.directive.ts

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,27 @@
11
import { Directive } from '@angular/core';
22

33

4-
/*
5-
*
6-
*/
74
@Directive({
85
/* tslint:disable-next-line:directive-selector */
96
selector: 'mk-input-group-label'
107
})
118
export class InputGroupLabelDirective {}
129

13-
/*
14-
*
15-
*/
10+
1611
@Directive({
1712
/* tslint:disable-next-line:directive-selector */
1813
selector: 'mk-input-group-addon-left'
1914
})
2015
export class InputGroupAddonLeftDirective {}
2116

22-
/*
23-
*
24-
*/
17+
2518
@Directive({
2619
/* tslint:disable-next-line:directive-selector */
2720
selector: 'mk-input-group-addon-right'
2821
})
2922
export class InputGroupAddonRightDirective {}
3023

31-
/*
32-
*
33-
*/
24+
3425
@Directive({
3526
/* tslint:disable-next-line:directive-selector */
3627
selector: 'mk-input-group-content'

library/angular-admin-lte/src/lib/form/input-group/input-group.module.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {FormsModule} from '@angular/forms';
33
import {CommonModule} from '@angular/common';
44

55
import {ColorModule} from '../../color/color.module';
6-
76
import {InputGroupComponent} from './input-group.component';
87
import {
98
InputGroupAddonLeftDirective,

library/angular-admin-lte/src/lib/form/input-text/input-text.directive.ts

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,8 @@ import { ClassService } from '../../services/class.service';
1313
providers: [ColorService, ClassService]
1414
})
1515
export class InputTextDirective implements OnInit {
16-
private defaultClass = 'form-control';
17-
private isSetClass: boolean;
18-
private onKeyUp = new Subject<NgControl>();
19-
20-
public onKeyup: Observable<NgControl> = this.onKeyUp.asObservable();
21-
2216
@Input() set borderColor(color: string) {
23-
this.colorService.setBackgroundColor(color, true, 'border-color', null);
17+
this.colorService.setBackgroundColor(color, true, 'border-color', '');
2418
}
2519
@Input() set class(className: string) {
2620
this.isSetClass = true;
@@ -30,14 +24,16 @@ export class InputTextDirective implements OnInit {
3024
this.colorService.setFontColor(color);
3125
}
3226

33-
/**
34-
* @method constructor
35-
* @param elementRef [description]
36-
* @param renderer2 [description]
37-
* @param ngControl [description]
38-
* @param colorService [description]
39-
* @param classService [description]
40-
*/
27+
private defaultClass = 'form-control';
28+
private isSetClass = false;
29+
private onKeyUp = new Subject<NgControl>();
30+
31+
public onKeyup: Observable<NgControl> = this.onKeyUp.asObservable();
32+
33+
@HostListener('keyup') keyUpListener(): void {
34+
this.onKeyUp.next(this.ngControl);
35+
}
36+
4137
constructor(
4238
public elementRef: ElementRef,
4339
public renderer2: Renderer2,
@@ -46,16 +42,9 @@ export class InputTextDirective implements OnInit {
4642
private classService: ClassService
4743
) {}
4844

49-
/**
50-
* @method ngOnInit
51-
*/
52-
ngOnInit() {
45+
ngOnInit(): void {
5346
if (!this.isSetClass) {
5447
this.classService.applyClasses(this.defaultClass);
5548
}
5649
}
57-
58-
@HostListener('keyup') keyUpListener() {
59-
this.onKeyUp.next(this.ngControl);
60-
}
6150
}

0 commit comments

Comments
 (0)