I've spent time looking on Google, Github, and Stackoverflow for a solution to this error, but I'm still struggling to fix it. Can anyone offer a suggestion or help?
Recently, I upgraded my Angular project from version 9 to version 10, and after the update, I started encountering errors like the ones below in a couple of modules.
Error: Property 'searchParameters' is being used before its initialization.
Code snippet: address: this.searchParameters?.address,
In short, here's a part of the code:
interface PartnerSearchParameters {
name?: string;
code?: string;
address?: string;
taxRegNumber?: string;
}
@Component({
selector: 'app-partner-search-list',
templateUrl: './partner-search-list.component.html',
styleUrls: ['./partner-search-list.component.scss']
})
export class PartnerSearchListComponent implements OnInit, AfterViewInit {
searchParameters: PartnerSearchParameters;
modelMainFilters = {
address: this.searchParameters?.address,
code: this.searchParameters?.code,
name: this.searchParameters?.name
taxRegNumber: this.searchParameters?.taxRegNumber ,
};
constructor(...){}
ngOnInit(): void {...}
...
}
The searchParameters are declared before modelMainFilters, where they are needed. I'm unsure about where the correct place to initialize them would be. Any ideas?