I am using Angular version 18.1.0 in a hybrid app mode environment (AngularJS + Angular 18)
I have the following code that take in input signal and compute a signal dependent on the input signal.
My component:
@Component({
selector: 'test-component',
standalone: true,
imports: [NgIf],
changeDetection: ChangeDetectionStrategy.OnPush
})
export class TestComponent {
form = input.required<FormGroup<TestFormModel>>();
testsCount = computed<number>(() => this.form().controls.tests.controls.length);
isLoading = computed<boolean>(() => {
if(this.form() && this.testsCount() !== null) {
return false;
} else {
return true;
}
});
constructor() {}
}
Template:
<div *ngIf="!isLoading()">
<span> Tests ({{ testsCount() }})</span>
</div>
Where the input come from (in the parent component that using the test component):
<test-component [form]="form" tabindex="0"></test-component>
I am not sure what I did wrong, but I kept getting the error from the ‘isLoading’ computed signal when the app is running:
TypeError: this.form is not a function
I not sure if the input signal is not being loaded from the parent component yet, and it is trying to compute the isLoading signal at the same time.
But I expect it to work as computed signal as it derived from input signal.