Sunday, 21 June 2020

Create a component without spec file in Angular 9

How to Create a component without spec file in Angular 9?


In the angular 9 there are two ways to do this.

1. By using angular CLI command

Just use following commands to remove spec file for generate component

ng generate component componentname --spec=false;


2. or using Angular.json

just use following command

ng config schematics.@schematics/angular:component.spec false


it will create following section in angular.json

Monday, 18 February 2019

How to update a column value with Autoincrement value in SQL server

How to update a column value with Autoincrement value in SQL server


As a full stack developer many time we face we accidently create a column with some value or we want to add column in table and provide the value in it with auto increment to we can do it with following query


DECLARE @counter int
SET @counter = 0
UPDATE Your_Table_Name
SET @counter = your_table_column_name = @counter + 1


Example:
DECLARE @counter int
SET @counter = 0
UPDATE [Policy].[MasterBroker]
SET @counter = brokerId = @counter + 1

Wednesday, 26 December 2018

Error: No ‘Access-Control-Allow-Origin’ Header is Present – Origin ‘localhost:…’ is therefore not allowed access

If you are using .net web api and again and again you build your's project and run that you will see that your's runs on different port after running you will be get following error in console window

Error: No ‘Access-Control-Allow-Origin’ Header is Present – Origin ‘localhost:…’ is therefore not allowed access.



this is very comman issue which can stuck  the developer in web api 
you can remove this by just configure the Global.asax file in Application_BeginRequest section  

by the following code in which we just configure the header section of the service


protected void Application_BeginRequest(object sender, EventArgs e){
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin","*"")
}

How to dynamically add and remove the validators from angular reactive forms?

For the Angular Developer most of the computer and learner want to know how to dynamically add and remove the validation in reactive Forms:

So the Angular provide the 3 set of the methods which can be used for this.

1. setValidators()
2. clearValidators()
3. updateValueAndValidity()


setValidators: setting the validation on the control on which you want to apply on this

clearValidators: If user want to remove the existing validations from the control then he
can use this method.

updateValueAndValidity: this method is always use when you set or clear the validation in
angular reactive forms.

for applying all the above method first we find the control in our typescript file by
following way

suppose on my component here is the HTML part of the phone control

<label class="radio-inline">
<input type="radio" value="phone" (click)="onContactPreferenceChange('phone')" formControlName="contactPreference" >Phone
</label>

Now on the ts file we will find the phone control by following way
const phoneControl = this.employeeForm.get('phone');

after this according to our need we can add or clear the validation from the control.

AdSense

The Ultimate Guide to Interceptors: Understanding Their Power and Functionality

  The Ultimate Guide to Interceptors: Understanding Their Power and Functionality An interceptor is a service that can intercept HTTP reques...

Follow