Published inCodeX·Nov 13Are you using useState the right way?useState, the React hook is one of the routine stuffs for a React developer. We, as React devs, know that it is used to trigger a re-render whenever the state changes. It’s simple, right? I mean, what could be complicated about that? …React4 min readReact4 min read
Published inCodeX·May 23Functional Resolvers in AngularResolvers in Angular are data providers that are used to pre-fetch data when the user is navigating through the application before Angular has rendered the desired page; i.e. it blocks the navigation until it’s resolved. The resolved data is accessible in the component through the ActivatedRoute class. Previously we used…Angular2 min readAngular2 min read
Published inCodeX·Oct 10, 2022How does Dependency Injection work in Angular?We all have used Dependency Injection irrespective of the tech stack, at some point in our coding journey. But what’s the reason for using it? Imagine instantiating a class each time we need to access it! Awful, yes! We use DI to avoid hard dependencies between classes. Dependency Injection ensures…Angular3 min readAngular3 min read
Published inCodeX·May 19, 2022Promises and more…People often confuse Promises to be asynchronous. But are they really asynchronous? Promises are arguably the most important concept of asynchronous programming in JavaScript, however, the execution of the callbacks passed into the Promise constructor is synchronous. Let’s understand the same with an example: Like you can see, when the…JavaScript3 min readJavaScript3 min read
Feb 15, 2022Unit testing for valueChanges of formControl in AngularThere can be n number of ways to trigger the valueChanges(). this.formName.get(‘form_control’).valueChanges .subscribe((changedValue: boolean) => { console.log(changedValue); this.formName.get(‘another_form_control’).setValue(‘’) }); Suppose this is the code that you want to cover in your test cases. Tried the setValue() and patchValue(); but for some reason, the subscription body is not covered in the…Angular1 min readAngular1 min read
Aug 24, 2021Angular Material MatSort in multiple tables. How to make it work properly?I was stuck with this issue for hours. The sorting didn’t work properly(worked after clicking 3–4 times for whatever reason), and at times sorting one table would affect the other as well(checked using console.log) If your multiple tables look like this: <table mat-table [dataSource]=”DataSource1” matSort (matSortChange)=”sortData($event)”> <table mat-table [dataSource]=”DataSource2” matSort (matSortChange)=”sortData($event)”>Angular1 min readAngular1 min read