Clear array elements in typrscript

After all my search, this is best way to clear elements in the array in type script.


arrayName.length =0

how to get child node value in xml using c#

Recently i need to get specific child node values from XML string in C#.


After spending some time i found a best way to parse the xml string to objects.

step 1 :
Include namespace
using System.Linq;

step 2:
Load xmlstring to XDocument, mean parse the string XDocument

step 3: 
By using linq with Descendants you can read specific child node values from xml string. 

READ CHILD NODES VALUES FROM XML WITH EXAMPLE


string s = @"<Root>
                        <Persons>
                            <Person ID=""1"">
                           <Name>Mishal</Name>
                            <Phone>860 9555 788</Phone>
                            <Email>abc@ac.com</Email>
                            </Person>
                            <Person>
                            <Name>Andy</Name>
                            <Phone>866 9555 788</Phone>
                            <Email>abc@abc.com</Email>
                            </Person>
                            </Persons>
                        </Root>";

            XDocument xmlString = XDocument.Parse(s);

            var root = (from obj in xmlString.Descendants("Person")
                        select new
                        {
                            Name = (string)obj.Element("Name"),
                            Phone = (string)obj.Element("Phone"),
                            Email = (string)obj.Element("Email")
                        }).ToList();

Read child nodes from xml string in C#

how to load xml string to xdocument

Today i have faced a situation that have to load xml string to XDocument.

But the Load method of XDocument doesn't support the string as a input parameter.

XDocument has another method called XDocument.Parse(xml), this method will accept xml string and parse them into an XDocument.

Example

string xmlString=  
@"<Root>  
    <ChildNode1>Value 1</Child>  
    <ChildNode2>Value 2</Child>  
    <ChildNode3>Value 3</Child>  
</Root>";  
XDocument xdocObj= XDocument.Parse(xmlString);  
Console.WriteLine(xdocObj);  


Hope this note sorted out your search on this issue.

Angular 4 Interview Questions for beginner

Angular 4 Interview Questions for beginner  - PART 1
1.       What is Angular?
2.       What is Single Page Application?
3.       What are Components in Angular 4?
4.       What are Bindings? Different type of bindings in Angular 4?
5.       What are Modules in Angular 4?
6.       What is CLI?
7.       What are Directives in Angular 4?
8.       What is Expression in Angular 4?
9.       What is the sequence of Angular Life Cycle hooks?
10.   What is the purpose of using package.json in the angular project?


Angular 4 Interview Questions for beginner  - PART 1
1.       What is Angular?

Angular 4 is a JavaScript framework which helps us to build web applications and apps in JavaScript, html, and Typescript, which is a superset of JavaScript.

Angular provides built-in features for animation, http service, and materials which in turn have features such as auto-complete, navigation, toolbar, menus, etc.

The code is written in Typescript, which compiles to JavaScript and displays the same in the browser.

2.       What is Single Page Application?


3.       What are Modules in Angular 4?
4.       What is CLI?
5.       What are Directives in Angular 4?
6.       What is Expression in Angular 4?
7.       What is the sequence of Angular Life Cycle hooks?
8.       What is the purpose of using package.json in the angular project?

Process with an ID #### is not running in visual studio


Process with an ID 10692 is not running 

  1. Close all the instance of visual studio by Exit button (Close properly visual studio)
  2. Open Visual studio by Run as administrator mode. 
  3. Try to debug now.  It will not throw any error.

Html 5 validation : Attribute ng-app is not a valid attribute of element body

Attribute 'ng-app' is not a valid attribute of element 'Body'

This is just a warning. You haven't enabled html5 in your application.That s why you are receiving this validation warnings.

Here i gave solution to rid out from this warnings.

After opened your MS VS, Select Tools->Options ->Text Editor- >HTML->Validation, Choose html5 in list, then restart your project.

If you are not find html5 in the list, you need to install html5, then do above step. Click here to down html5.

Again you are receiving such that warining, then prepend data- to the attribute name (e.g. data-ng-app, the warning lines gets disappear.

Attribute ng-app is not a valid attribute of element Div

Attribute 'ng-app' is not a valid attribute of element 'Div'

This is just a warning. You haven't enabled html5 in your application.That s why you are receiving this validation warnings.

Here i gave solution to rid out from this warnings.

After opened your MS VS, Select Tools->Options ->Text Editor- >HTML->Validation, Choose html5 in list, then restart your project.

If you are not find html5 in the list, you need to install html5, then do above step. Click here to down html5.

Again you are receiving such that warining, then prepend data- to the attribute name (e.g. data-ng-app, the warning lines gets disappear.

Validator. Pattern for only numbers in angular 4

We usually validate the form control by using Validator component from angular/forms.

formControlAge = new FormControl('',[
(control : AbstractControl) => Validators.pattern(`[0-9]+[A-Z]?`)])

count of digits after decimal points

Here we have an example to find out the number of digits that come after decimal points.

string number = "253.1258";
int length = number.Substring(number.IndexOf(".")+1).Length;

CSS colon expected in app.component.css

This is the issue i am facing right now. I will update this once i got solution.

What is Transpiling in Angular?

Compiling
is the general term for taking source code written in one language and transforming into another.

Transpiling
is a specific term for taking source code written in one language and transforming into another language that has a similar level of abstraction.


Transpiling is the process of converting the typescript into javascript (using Traceur, a JS compiler). 

Though typescript is used to write code in the Angular applications, the code is internally transpiled into javascript. 

npm - Overview

What is npm?


npm help us(developers) to share and reuse code, and makes it easy to update the code that we already shared.

Install npm

In order to install npm, just install node.js. when you install Node.js, you automatically get npm installed on your computer because npm is distributed with Node.js

Click Here to download node.js

Verify

After installation just verify that you have node.js in your machine.
                  node -v (or) npm -v

find out npm version
Good to have the npm version 8 & above. 

Use below command to update npm version
              npm install npm@latest -g 

CONVERT VS TRY_CONVERT IN SQL 2012

TRY_CONVERT - It help us to convert to specific data type, it is most similar to CONVERT(). The only difference and advantage is it will return NULL when its fail to convert into given data type. 

Eq.







Setup new angular project

Step 1 - Install npm

In order to install npm, just install node.js. when you install Node.js, you automatically get npm installed on your computer because npm is distributed with Node.js

Click Here to download node.js

After installation just verify that you have node.js in your machine.
node -v (or) npm -v

Step 2 - Install Angular CLI 

CLI - Command Line Interface.

CLI - It is a Tool, which is used to create, develop and maintain angular applications.

npm install -g @angular/cli - This is the command used to install angular CLI.

npm -v - This is command used to get version of NPM.

Create a new angular project
ng new ProjectName


command to Create a angular project


Run a Project
   Open your angular project through command prompt and then type below command to run the project
To run angular project

ng s --o 
or 
ng serve --open

--------------------------
Terminate the Job

Ctrl +C

---------------------------


Open closed document in MS SQL SERVER



We can retrieve the query even we closed our query window in SQL without saving the script.

SELECT execquery.last_execution_time AS [Date Time], execsql.text AS [Script] FROM sys.dm_exec_query_stats AS execquery
CROSS APPLY sys.dm_exec_sql_text(execquery.sql_handle) AS execsql
ORDER BY execquery.last_execution_time DESC

Above query provides a list of scripts and its time of execution in the last 24 hours. 

This will be work for all executed scripts not only a view or procedure.

isNAN function in javascript

isNAN function checks the argument and returns true if the argument is not a number else return false


Example of isNAN()

var val='04cs';

if(isNAN(val))
{
alert('this is not a number') ;
}else{
alert('this is a number') 

}


ANS : this is not a number


var value='0411';

if(isNAN(value))
{
alert('this is not a number') ;
}else{
alert('this is a number') 

}


ANS : this is a number

undefined value and null value

undefined means a variable has been declared but has not yet been assigned a value. On the other hand, null is an assignment value. It can be assigned to a variable as a representation of no value.

Also, undefined and null are two distinct types: undefined is a type itself (undefined) while null is an object.


Unassigned variables are initialized by JavaScript with a default value of undefined. JavaScript never sets a value to null. That must be done programmatically.

undefined check not working in javascript

Checking undefined is not work when we go normal if statement, As like below

var id=$('#txt').val();

if(id != 'undefined')
{
// Our Code
}

"id" is var type, i.e mean unknown type, such as whether "id" is string, numeric, or even undefined.  
if "txt" is not defined in the page, then id's value is  undefined, so we shall check the type of operand with value.

By using "typeof" operator we resolve above issue. The "typeof" operator in JavaScript/Jquery allows you to probe the data type of its operand.

var item = 10;
alert(typeof item); This returns the type of item not value.


if(typeof id != 'undefined')
{
// Our Code


I hope this will help you to resolve the problem.

How to check if a variable is NOT undefined

Checking undefined is not work when we go normal if statement, As like below

var id=$('#txt').val();

if(id != 'undefined')
{
// Our Code
}

"id" is var type, i.e mean unknown type, such as whether "id" is string, numeric, or even undefined.  
if "txt" is not defined in the page, then its value is  undefined is a one of type, so we shall check the type of operand with value.

By using "typeof" operator we resolve above issue. The "typeof" operator in JavaScript/Jquery allows you to probe the data type of its operand.

var item = 10;
alert(typeof item); This returns the type of item not value.


if(typeof id != 'undefined')
{
// Our Code


I hope this will help you to resolve the problem.

What's the main difference between int.Parse() and Convert.ToInt32

string str = "199"

int.Parse(str)

  1. This method converts the string to integer. 
  2. If string variable 'str' is null, then it will throw ArgumentNullException. 
  3. If string 'str' has out of integer ranges, then it will throw OverflowException.
  4. If string 'str' is other than integer value, then it will throw FormatException. 


Convert.ToInt32(str)

  1. This method converts the string to integer. 
  2. If string str is null, then it will return 0 rather than throw ArgumentNullException.
  3. If string str represents out of integer ranges, then it will throw OverflowException. 
  4. If string str is other than integer value, then it will throw FormatException.