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.

Friday 21 December 2018

How to find out how many data are in the colums are in the upper case in sql server

In Most of the interview, Interviewer asked write down a query to find out the how many rows have upper case data.


so here is the answer to crack this question in the interview.


select * from T(table_name)
  where fld(coloum_name) = upper(fld) collate SQL_Latin1_General_CP1_CS_AS
You can force to check the case sensitive collation.

Wednesday 19 December 2018

what is best way to deal with set a value in ReactiveForm?

Most of the angular developer say the which is the best way to set a value of reactive form
1. setvalue() or patchValue()

In my opinion patchValue() is the best way to initialize the reactive form because if accidently developer miss to assign a value of field in reactive form user get the error with dealing with setValue() method.
on the other hand if we deal with patchValue() user can not get any type of error if he accidently miss to assign any fileld in the form.

Problem: Must supply a value for form control with name 'say xyz'

Most of the angular developer face the above problem when they are dealing with Reactive forms

"Must supply a value for form control with name /......"

this is because we donot provide the all field value that are in the reactive form and we are using the setValue method in angular.

this problem can be solved by two ways.
1. you can provide the value of all form control that you are using with reactive form.
2. or in your's case you want to provide the value for the some set of formcontrol then instead of using setValue() we can use patchValue() for loading the data

Problem: Can't bind to 'formGroup' since it isn't a known property of 'form'.

Can't bind to 'formGroup' since it isn't a known property of 'form'.


Most comman problem in angular is : 'Can't bind to 'formGroup' since it isn't a known property of 'form'.'

this is because formGroup and formControl directive are provided by angular reactiveform

and probably you did not include this is your's angular app. so first you include this in your's angular app so that this error is gone

so include the reactive form directive in your's app.component.module by following way

import { ReactiveFormsModule } from "@angular/forms";

and also include this in imports array so your's
app.module.ts would we look like this


import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from "@angular/forms";

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { CreateEmployeeComponent } from './employee/create-employee.component';
import { ListEmployeesComponent } from './employee/list-employees.component';

@NgModule({
declarations: [
AppComponent,
CreateEmployeeComponent,
ListEmployeesComponent
],
imports: [
BrowserModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }


and also include the FormGroup and FormControl in your's component.ts
in my case it is create-employee.component.ts
have a look
import { Component, OnInit } from '@angular/core';
import { FormGroup, FormControl } from "@angular/forms";
@Component({
selector: 'app-create-employee',
templateUrl: './create-employee.component.html',
styleUrls: ['./create-employee.component.css']
})
export class CreateEmployeeComponent implements OnInit {
employeeForm: FormGroup;
constructor() { }

ngOnInit() {
this.employeeForm = new FormGroup({
fullName: new FormControl(),
email: new FormControl()
})
}
onSubmit(): void {
console.log(this.employeeForm.value);
}

}

Now i can hope that your's error should be gone. enjoy......

Wednesday 12 December 2018

can we use cookie concept in angular

Yes we can use the cookies in angular also angular cookies is much similiar as Angular 1.x but in angular 2,4 and 6 there is one extraa method is DeleteAll.
Angular uses the following method for cookie


1.      Check – This method is used to check the cookie existing or not.
2.      Get - This method returns the value of given cookie name.
3.      GetAll - This method returns a value object with all the cookies
4.      Set – This method is used to set the cookies with a name.
5.      Delete – This method used to delete the cookie with the given name
6.      deleteAll – This method is used to delete all the cookies
7.      and so on  

Thursday 11 October 2018

What is the Magic Table in Sql server ?

What is the Magic Table in Sql server ?

Ans :- Magic table are the temporary object created by server internally to hold recently  inserted value in case of inserted or hold the deleted value in case of deleted or to hold the updated value in case of updated.


Let suppose if we want to create trigger on the table on insert or delete. so on insertion of a record into that table the inserted table will be created automatically by the sql server database, on deletion of record from the table the deleted table will be created automatically by the database

so these 2 table inserted and deleted are called magic table.

these table are not a physical table these are only internal table.




Tuesday 9 October 2018

Most commonly asked interview question on ,net and angular 2

Comman interview question for .net and angular 2



Hi friends here i am providing the list of the some question that are commonly asked for every .net and angular 2 developer for the 2-3 years of experience

1. FirstorDefault in Linq
2. Difference between design principle and design patterns
3. Viewchild in angular 2
4. Difference between promise and subscribe & observables
5. How to change layout page dynamically in view
Q1 . Difference between common.js and system.js in ES2015
Q2 . How can we replace the http service with custom service.
Q3 . Optional parameters in javascript
Q4 . Function overloading in typescript.
Q5 . Difference between observables and promise.
Q6 . Enable experimental metadata support in angular
Q7 . Generics in typescript.
Q8 . Oninit and OnDestroy.
Q9 . @Injectable in angular
Q10 . Default access specifier in typescript.
Q11 . Routing guard in angular.
Q12 . Pipe and async pipes in angular.
Q13 . Declaration files in typescript.
Q14 . Inheritance in typescript.
Q15 . Interface in typescript.
Q16 . How can we expose input & output properties for a component so that they consumed by other components
Q17 . RXJS map,switchingmap,mergemap,from,of,zip,empty,throw.
Q18 . Uniontype & tuple in javascript
Q19 . Interceptor.
Q20 . Routing resolver.
Q21 . Custom pipes
Q22 . optional and default parametres in javascript?
Q23 what is canActive and resolver in angular?
Q24 Benefit of using Angular route Resolver?
Q25 What is auth Guard ?
Q26 Why the company required MVC pattern with angular?
Q27 what is async pipe in angular?
Q28 what is template string?  -- template string is used which lets define the multiline string
     Eg:
    @Component({
  selector: 'joke',
  template: `
  <h1>What did the cheese say when it looked in the mirror?</h1>
 <p>Halloumi (hello me)</p>
  `
})


c#
Q29 How to make generic class that should have parameter less constructor?


Q30 What is the Extension method in C#?
Q31 How to invoke directives in angular?
Q32 What is service and factory in angular?
Q33 What is var keyword in c#?

Q34 What is the difference between string and StringBuilder?
Q35 what is the use of observable and the promise and why we use observable instead we have promise
Q36. why function is there is sql if we have stored procedure in that?

Friday 5 October 2018

Can't bind to 'formGroup' since it isn't a known property of 'form'.

Can't bind to 'formGroup' since it isn't a known property of 'form'. 


this error is because both
formGroup and formControl  directive are belongs to reactive forms module and you have not import this ReactiveFormModule in your's Angular application so this type of error occurred.


Import this module in your's app.module like this.



import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';

import { AppComponent } from './app.component';
import { CreateEmployeeComponent } from './employee/create-employee/create-employee.component';
import { ListEmployeeComponent } from './employee/list-employee/list-employee.component';
import { AppRoutingModule } from './/app-routing.module';

@NgModule({
declarations: [
AppComponent,
CreateEmployeeComponent,
ListEmployeeComponent
],
imports: [
BrowserModule,
AppRoutingModule,
ReactiveFormsModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }

Thursday 4 October 2018

router-outlet is not a known element

'router-outlet' is not a known element


If you getting this type of error in your's angular project when you configure your router module file.

then just check the routing module file and check the import and export array.

you must be declare the RouterModule in your's export array.

In my case app.routing module file 


@NgModule({
imports: [
RouterModule.forRoot(appRoutes),
],
exports: [
RouterModule
]

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