Wednesday, 26 December 2018

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
]

Wednesday, 26 September 2018

How to find duplicate column values with number of occurance in table

Hi user
below i am showing how to get duplicate record from the table with number of the occurrence in that column


suppose that i have two table one is employee and other one have emp_details

employee table have the master data like employee id ,name and other info and emp_details table have secondary information like address and salary so now my question in this to find out the salary that have duplicate entry


so according to my table structure i have following data in employee table

Emp id
FirstName
Last Name
Emp code
Position
location
1
Neeraj
Upadhyay
GCS-1795
Software Developer
Noida
2
Akhilesh
Upadhyay
GCS-1796
Software Developer
Delhi
3
Ashish
Bhisht
GCS-1797
Software Developer
Sawai madhopur
1002
Akash
Srivastava
GCS-1798
Software Developer
Kota
1003
Dikhsa
Rawat
GCS-1799
Software Developer
Naguar
1004
Vaishali
Gupta
GCS-1800
Software Developer
Aligarh


now the data in emp_details table
Emp_id
Address
Salary
1
behind old laxman mandir bharatpur rajasthan
50000
2
WZ-85 Todapur New delhi
50000
3
kerapati mohalla bharatpur
40000
1002
A-154/A sector 63 noida
55000
1003
india habitat center lodhi road new delhi
35000


So now we find the duplicate salary in both the table
so we execute following code


select salary,count(*) as duplicate from Employee inner join emp_details
on Employee.EmployeeID=Emp_details.emp_id
group by salary
having (COUNT(*)>1)

Saturday, 15 September 2018

What is the ref and Out keyword in C#?

consider the following program to understand the out and ref keyword of C#

using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace simplevalue
{
    class Progra {
      static void Addvalue(int val)
        {
             val++
        }
      static
 void Main(string[] args)
       {
            int
 value = 10;
            Addvalue(value);
            Console.WriteLine(value);
            Console.Read();
        }
    }
}


in the above program the output of the above program is 10. because we provide the value variable to 10 after that we provide this value to Addvalue() function and in that they increment the value by 1 and become 11. but this value is never carried out to this function because we copy the value variable not reference to the variable. this is default working of the C# language .
we preferred this type of output in most of the scenario but in some cases where we want to modify the variable then we use ref and out keyword for this.

The out and ref keyword are looks quite similar in nature. Both parameters are used to return back some value to the caller of the function. But still there is a small but important difference between them. Both of the parameter type has been kept in the C# language for specific scenario.

Out keyword:
The out parameter can be used to return the values in the same variable  as a parameter of the method. Any changes made to the parameter will be reflected in the variable.
The out keyword causes arguments to be ed by reference. This is similar to the ref keyword, except that ref requires that the variable be initialized before being ed. To use an out parameter, both the method definition and the calling method must explicitly use the out keyword. 

example:
 static void Main(string[] args)
        {
            int value;
            AddValue( out value);
            Console.WriteLine(value);

            Console.Read();
        }
        static void AddValue(out int val)
        {
            val = 20; 
        }

ref keyword: 
The ref keyword on a method parameter causes a method to refer to the same variable that was ed as an input parameter for the same method. If you do any changes to the variable, they will be reflected in the variable.
The ref keyword is similer to out keyword but ref requires that the variable be initialized before being ed.
 
For example
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace outexample
{
    class Program    {
        static void value(ref int val)
        {
           val = 20;
        }
    static
 void Main(string[] args)
        {
            int value;
            value(ref value);
            Console.WriteLine(value);     
           Console.Read();
        }
    }
}

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