Skip to content

Commit 6b74c32

Browse files
committed
refactor(form): signal inputs, host bindings, cleanup
1 parent 1f28686 commit 6b74c32

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { FormDirective } from './form.directive';
2+
import { TestBed } from '@angular/core/testing';
23

34
describe('FormDirective', () => {
45
it('should create an instance', () => {
5-
const directive = new FormDirective();
6-
expect(directive).toBeTruthy();
6+
TestBed.runInInjectionContext(() => {
7+
const directive = new FormDirective();
8+
expect(directive).toBeTruthy();
9+
});
710
});
811
});
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
import { booleanAttribute, Directive, HostBinding, Input } from '@angular/core';
1+
import { booleanAttribute, computed, Directive, input } from '@angular/core';
22

33
@Directive({
4-
selector: 'form[cForm]'
4+
selector: 'form[cForm]',
5+
host: { '[class]': 'hostClasses()' }
56
})
67
export class FormDirective {
78
/**
89
* Mark a form as validated. If you set it `true`, all validation styles will be applied to the form. [docs]
910
* @type boolean
1011
* @default false
1112
*/
12-
@Input({ transform: booleanAttribute }) validated: string | boolean = false;
13+
readonly validated = input(false, { transform: booleanAttribute });
1314

14-
@HostBinding('class')
15-
get hostClasses(): any {
15+
readonly hostClasses = computed(() => {
1616
return {
17-
'was-validated': this.validated
17+
'was-validated': this.validated()
1818
};
19-
}
19+
});
2020
}

0 commit comments

Comments
 (0)