How to Count Items or Certain Items in JavaScript Array?
Count Items in Array You can simply check length of array to count items in JavaScript array.
function CountItems(arr){ return arr.length; } Count Certain Item in Array To count certain item in an Array you can make use of Array filter method to find item in Array.
function CountItems(arr, item=null){ if(item == null) return arr.length; let filteredResult = arr.filter(i => i == item); return filteredResult.
[Read More]
Error: Unexpected value FormBuilder imported by the module DynamicTestModule. Please add an @NgModule annotation.
During unit testing in Angular, I got the below error:
b Error: Unexpected value ‘FormBuilder’ imported by the module ‘DynamicTestModule’. Please add an @NgModule annotation.
Import the following modules to resolve the error,
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { BrowserModule } from '@angular/platform-browser'; Here is the complete spec file,
import { TestBed, async } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { AppComponent } from '.
[Read More]
LAMP vs MEAN: Which Tech Stack Should You Choose?
LAMP vs MEAN: Which Tech Stack Should You Choose? Businesses around the world require enterprise-level applications, websites, and servers to run their everyday operations smoothly. Whenever a business is planning to create a web app, then they should choose a standardized tech stack that is consistent and scalable.
The tech stack is nothing but a collection of technologies or software that are used in a systemized way to build a web application.
[Read More]
NullInjectorError: R3InjectorError(DynamicTestModule)[FormBuilder -> FormBuilder]:NullInjectorError: Noprovider for FormBuilder!
While doing Angular unit testing I got the following error:
b NullInjectorError: R3InjectorError(DynamicTestModule)[FormBuilder -> FormBuilder]:NullInjectorError: Noprovider for FormBuilder!
You can resolve the following error by importing the following modules,
import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { BrowserModule } from '@angular/platform-browser'; Here is the complete spec file,
import { TestBed, async } from '@angular/core/testing'; import { RouterTestingModule } from '@angular/router/testing'; import { AppComponent } from './app.component'; import { HttpClientTestingModule } from '@angular/common/http/testing'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { BrowserModule } from '@angular/platform-browser'; import { ServService } from '.
[Read More]
Writing Readable JavaScript Code
Writing Readable JavaScript Code
A lot of times I have seen developers looking at the existing code base and say they can’t make sense of the existing code. If we keep a certain set of rules and standards in mind, we can write code which is easy to read and understand.
In this article, we’ll discuss about certain things that every web developer should keep in mind while developing web applications.
[Read More]
Cant bind to formGroup since it isnt a known property of form
Can’t bind to formGroup since it isn’t a known property of form
The above error is shown in your Angular application when you forget to import FormsModule and ReactiveFormsModule in your module file app.module.ts.
import { NgModule } from '@angular/core'; import { BrowserModule } from '@angular/platform-browser'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { MatTabsModule } from '@angular/material/tabs'; import { NewEmployeeComponent } from '.
[Read More]
Clear Cache in NPM
How to clear cache in Npm?
First try running the following command to verify the npm cache.
npm cache verify
It shows the size and path of the npm cache.
C:\Users\Jay>npm cache verify
Cache verified and compressed (~\AppData\Roaming\npm-cache\_cacache):
Content verified: 7736 (873243019 bytes)
Content garbage-collected: 5209 (1044405556 bytes)
Index entries: 13079
Finished in 26.299s
Now to delete the npm cache you can run the following,
npm cache clean --force
Conditional Rendering in Angular Using *ngIf
How to conditionally render HTML in Angular ?
You can make use of ngIf,ng-template and ng-container to conditionally render HTML.
If you simply want to render some HTML if a condition is satisfied you can use ngIf and ng-container
<ng-container *ngIf="showEmployee"> <h3> Data is here !! </h3> </ng-container> If you also have an else block, you can make use of ng-container and ng-template.
<ng-container *ngTemplateOutlet="showEmployee ? ifblock : elseblock"> </ng-container> <ng-template #ifblock> <h3> If Data is here !
[Read More]
DataTypes in JavaScript
JavaScript is a loosely typed language wherein a variable can be assigned any type of value. For example,
let name = "Funny Name"; // can have string value name = 100 // can have integer value name = true // can have boolean Data types in JavaScript are divided into two categories, Primitive types and Objects.
Primitive Types - Immutable Types Primitive consists of all the data types which cannot be modified or are immutable.
[Read More]
Difference between Pass by Value and Pass by Reference in JavaScript
Difference between Pass by Value and Pass by Reference in JavaScript.
Pass by Value Primitive data types like String, Number, Boolean etc. are immutable or cannot be changed once defined. When you define a primitive data type memory is allocated to it. On assigning it to another variable it’s copied and another memory is allocated for the copy.
Let’s try to understand with the help of an example,
let a = 100; let b = a; a = 90; console.
[Read More]