Monday, May 27, 2019

lEARNING: SQL | WHERE Clause

SQL | WHERE Clause

WHERE keyword is used for fetching filtered data in a result set.
  • It is used to fetch data according to a particular criteria.
  • WHERE keyword can also be used to filter data by matching patterns.
Basic Syntax:
SELECT column1,column2 FROM table_name WHERE column_name operator value;
column1 , column2: fields int the table
table_name: name of table
column_name: name of field used for filtering the data
operator: operation to be considered for filtering
value: exact value or pattern to get related data in result 
List of operators that can be used with where clause:


operator description
> Greater Than
>= Greater than or Equal to
< Less Than
<= Less than or Equal to
= Equal to
<> Not Equal to
BETWEEN In an inclusive Range
LIKE Search for a pattern
IN To specify multiple possible values for a column
table1
Queries
    • To fetch record of students with age equal to 20
      SELECT * FROM Student WHERE Age=20;
      
      Output:
      ROLL_NO NAME ADDRESS PHONE Age
      3 SUJIT ROHTAK XXXXXXXXXX 20
      3 SUJIT ROHTAK XXXXXXXXXX 20



  • To fetch Name and Address of students with ROLL_NO greater than 3
    SELECT ROLL_NO,NAME,ADDRESS FROM Student WHERE ROLL_NO > 3;
    
    Output:
    ROLL_NO NAME ADDRESS
    4 SURESH Delhi
BETWEEN operator
It is used to fetch filtered data in a given range inclusive of two values.
Basic Syntax:
SELECT column1,column2 FROM table_name WHERE column_name BETWEEN value1 AND value2;
BETWEEN: operator name 
value1 AND value2: exact value from value1 to value2 to get related data in
result set.

Queries
  • To fetch records of students where ROLL_NO is between 1 and 3 (inclusive)
    SELECT * FROM Student WHERE ROLL_NO BETWEEN 1 AND 3;
    
    Output:
    ROLL_NO NAME ADDRESS PHONE Age
    1 Ram Delhi XXXXXXXXXX 18
    2 RAMESH GURGAON XXXXXXXXXX 18
    3 SUJIT ROHTAK XXXXXXXXXX 20
    3 SUJIT ROHTAK XXXXXXXXXX 20
    2 RAMESH GURGAON XXXXXXXXXX 18

  • To fetch NAME,ADDRESS of students where Age is between 20 and 30 (inclusive)
    SELECT NAME,ADDRESS FROM Student WHERE Age BETWEEN 20 AND 30;
    
    Output:


    NAME ADDRESS
    SUJIT Rohtak
    SUJIT Rohtak
LIKE operator
It is used to fetch filtered data by searching for a particular pattern in where clause.
Basic Syntax:
SELECT column1,column2 FROM table_name WHERE column_name LIKE pattern;
LIKE: operator name 
pattern: exact value extracted from the pattern to get related data in
result set.
Note: The character(s) in pattern are case sensitive.
Queries
  • To fetch records of students where NAME starts with letter S.
    SELECT * FROM Student WHERE NAME LIKE 'S%'; 
    The ‘%'(wildcard) signifies the later characters here which can be of any length and
    value.More about wildcards will be discussed in the later set.
    Output:
    ROLL_NO NAME ADDRESS PHONE Age
    3 SUJIT ROHTAK XXXXXXXXXX 20
    4 SURESH Delhi XXXXXXXXXX 18
    3 SUJIT ROHTAK XXXXXXXXXX 20
  • To fetch records of students where NAME contains the patter ‘AM’.
    SELECT * FROM Student WHERE NAME LIKE '%AM%';
    
    Output:


    ROLL_NO NAME ADDRESS PHONE Age
    1 Ram Delhi XXXXXXXXXX 18
    2 RAMESH GURGAON XXXXXXXXXX 18
    2 RAMESH GURGAON XXXXXXXXXX 18
IN operator
It is used to fetch filtered data same as fetched by ‘=’ operator just the difference is that here we can specify multiple values for which we can get the result set.
Basic Syntax:
SELECT column1,column2 FROM table_name WHERE column_name IN (value1,value2,..);
IN: operator name 
value1,value2,..: exact value matching the values given and get related data in result set.
Queries
  • To fetch NAME and ADDRESS of students where Age is 18 or 20.
    SELECT NAME,ADDRESS FROM Student WHERE Age IN (18,20);
    
    Output:
    NAME ADDRESS
    Ram Delhi
    RAMESH GURGAON
    SUJIT ROHTAK
    SURESH Delhi
    SUJIT ROHTAK
    RAMESH GURGAON
  • To fetch records of students where ROLL_NO is 1 or 4.
    SELECT * FROM Student WHERE ROLL_NO IN (1,4);
    
    Output:
    ROLL_NO NAME ADDRESS PHONE Age
    1 Ram Delhi XXXXXXXXXX 18
    4 SURESH Delhi XXXXXXXXXX 18

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

Sunday, May 26, 2019

Declaring Variables

Declaring Variables

int myAge;
String myName;
boolean isTired;
Variable definitions can go anywhere in a method definition (that is, anywhere a regular Java
statement can go), although they are most commonly declared at the beginning of the definition
before they are used:
public static void main (String args¸]) {
int count;
String title;
boolean isAsleep;
...
}
You can string together variable names with the same type:
int x, y, z;
String firstName, LastName;
You can also give each variable an initial value when you declare it:
int myAge, mySize, numShoes = 28;
String myName = “Laura”;
boolean isTired = true;
int a = 4, b = 5, c = 6;
If there are multiple variables on the same line with only one initializer (as in the first of the
previous examples), the initial value applies to only the last variable in a declaration. You can also
group individual variables and initializers on the same line using commas, as with the last
example, above.
Local variables must be given values before they can be used (your Java program will not compile
if you try to use an unassigned local variable). For this reason, it’s a good idea always to give local
variables initial values. Instance and class variable definitions do not have this restriction (their
initial value depends on the type of the variable: null for instances of classes, 0 for numeric
variables, ‘\0’ for characters, and false for booleans).


Notes on Variable Names
 
Variable names in Java can start with a letter, an underscore (_), or a dollar sign ($). They cannot
start with a number. After the first character, your variable names can include any letter or
number. Symbols, such as %, *, @, and so on, are often reserved for operators in Java, so be careful
when using symbols in variable names.

Thursday, January 17, 2019

20+ Frequently Asked AngularJS Interview Questions and Answers

20+ Frequently Asked AngularJS Interview Questions and Answers

 

AngularJS can be a demanding technology, prompting a salary scope of anything from $60/hour for a freelance developer to $70,000/year for a Front End Developer/Engineer in an organization. Since this certification is a requirement for a large percentage of web-developer job postings, you can assume that there is never a lack of qualified candidates.
In every interview, you will have to contend with fierce competition. To perform well and get your dream job, you have to prepare in advance. To help you, we’ve outlined 20 frequently asked AngularJS interview questions and the kind of answers your interviewer is likely looking for.
1. In 30 seconds, define AngularJS.
AngularJS is an open-source JavaScript framework designed for creating dynamic single web page applications with fewer lines of code.
2. Mention some advantages of using AngularJS framework.
Some of the key advantages of using AngularJS framework include:
  • It provides a great “desktop-like” experience to the end user.
  • By separating DOM manipulation from app logic, it makes code modular and easy to test.
  • It supports two-way data binding.
3. What is the main thing that you would need to change if you were migrating from AngularJS 1.4 to AngularJS 1.5? 
To adapt to the new AngularJS 1.5 components, you would need to change .directive to .component
4. Is AngularJS compatible with all browsers? 
Yes.
5. What are the key features of AngularJS?



AngularJS, the self-proclaimed “superheroic JavaScript MVW framework,” has been around since 2009 and it remains one of the most popular web development frameworks the world over. According to Indeed.com, the demand for developers has been on the rise in recent months and this trend is expected to continue.
AngularJS can be a demanding technology, prompting a salary scope of anything from $60/hour for a freelance developer to $70,000/year for a Front End Developer/Engineer in an organization. Since this certification is a requirement for a large percentage of web-developer job postings, you can assume that there is never a lack of qualified candidates.
In every interview, you will have to contend with fierce competition. To perform well and get your dream job, you have to prepare in advance. To help you, we’ve outlined 20 frequently asked AngularJS interview questions and the kind of answers your interviewer is likely looking for.
1. In 30 seconds, define AngularJS.
AngularJS is an open-source JavaScript framework designed for creating dynamic single web page applications with fewer lines of code.
2. Mention some advantages of using AngularJS framework.
Some of the key advantages of using AngularJS framework include:
  • It provides a great “desktop-like” experience to the end user.
  • By freeing the developer from having to register callbacks manually or write repetitive low-level DOM manipulation tasks, it saves months of development.
  • By separating DOM manipulation from app logic, it makes code modular and easy to test.
  • It supports two-way data binding.
3. What is the main thing that you would need to change if you were migrating from AngularJS 1.4 to AngularJS 1.5? 
To adapt to the new AngularJS 1.5 components, you would need to change .directive to .component
4. Is AngularJS compatible with all browsers? 
Yes.
5. What are the key features of AngularJS?
  • Scope
  • Controller
  • Model
  • View
  • Services
  • Data Binding
  • Directives
  • Filters
  • Testable
6. Define scope in AngularJS.
Scope is a special JavaScript object that plays the role of joining the controller (JavaScript) with the views (HTML). The controller sets properties on the scope and the view binds to them.
7. Explain the concept of scope hierarchy.
Each AngularJS application has only one root scope. Child controllers, however, create a scope for each view. When the new scopes are created, they are added to their parent root scope as child scopes. This creates a hierarchical structure when they are attached.
8. What is data binding in AngularJS and What is the difference between one-way and two-way binding?
Data binding is the automatic attunement of data between the view and model components. AngularJS uses two-way data binding. In one-way binding, the scope variable in the html is set to the first value that its model is assigned to.
In two-way binding, the scope variable changes its value every time its model binds to a different value.
9. What are directives? 
Directives are special markers on a DOM element that tell the html compiler to attach a specified behavior to the DOM element. Directives start with ng-prefix. Some of the built-in directives include ngClass, ngApp, ngRepeat, ngModel, ngBind and ngInit
10. List the different types of directives.
There are four types of directives:
  • Comment directives
  • CSS class directives
  • Attribute directives
  • Element directives
11. In what ways can you use a directive? 
You can use a directive as an element, attribute or class name. To define the way your directive will be used, you need to set the restrict option in the directive declaration. The restrict option can be set to:
‘A’ - Only matches attribute name
‘C’ - Only matches class name
‘E’ – Only matches element name
You can combine these restrictions to produce needed results.
12. Explain what a digest cycle is in AngularJS?
During every digest cycle, all new scope model values are compared against the previous values. This is called dirty checking. If change is detected, watches set on the new model are fired and another digest cycle executes. This goes on until all models are stable.
The digest cycle is triggered automatically but it can be called manually using “.$apply()”.
13. Which are the common ways of communication between modules of your application, using core AngularJS functionality?
The common ways of communication include:
  • Using events
  • Using services
  • By assigning models on $rootScope
  • Directly between controllers using ControllerAs and other forms of inheritance
  • Directly between controllers using $parent, $$childHead, $$nextSibling
14. Explain what the link function is and how it differs from compile.
The link function combines the directives with a scope to produce a live view.
The link function is responsible for instance DOM manipulation and for registering DOM listeners.
The compile function is responsible for template DOM manipulation as well as the collection of all the directives.
15. Explain e2e testing of AngularJS applications.
End-to-end (e2e) testing involves testing an application from start to finish to determine whether all the components are working properly. It catches issues within an application related to integration and flow.
16. What is dependency injection?
Dependency injection is the process where the dependent objects are injected rather than being created by the consumer.
17. What are the benefits of dependency injection?
Dependency injection has two major benefits: Testing and decoupling.
18. What is Single Page Application (SPA)? 
SPA is the concept whereby pages are loaded from the server not by doing post backs, rather by creating a single shell page or master page and loading the web pages into the master page.
19. How can SPA be implemented in AngularJS?
SPA can be implemented with Angular by using Angular routes
20. How can digest cycle time be decreased?
Digest cycle time can be decreased by decreasing the number of watchers. To do this you can:
  • Use web worker
  • Work in batches
  • Cache DOM
  • Remove unnecessary watchers
  • Use one-time Angular binding

Conclusion

Now that you’ve read all the AngularJS interview questions and answers above, you are a step closer to passing your interview and getting your dream job.
If you feel that you need to refresh your knowledge on some concepts and master front-end web development with Angular, consider taking  Angular Certification training course. It’s affordable and

Angular 6 Interview Questions

Angular 6 Interview Questions

#1 Question

List some new features comes with Angular6

Latest Key features of Angular 6
  • Added support for creating Custom Elements based on Angular Components.
  • Animations: expose element and params within transition matchers.
  • Bazel: change ng_package rule to APF v6
  • singleline, multiline and jsdoc comments are now supported
  • compiler-cli : add resource inlining to ngc
  • support for TypeScript 2.7
  • Require node 8 as runtime engine

#2 Question

Explain Ivy Renderer in Angular?

#3 Question

What is Bazel and Closure Compiler in Angular6?

#4 Question

Explain Service Worker in reference to Angular JS

#5 Question

Write command to generate a component in specific module in Angular cli?

You can generate a component in specific module in AngularJs by running below commnad on CLI.
ng g component component_name --module=module_name

#6 Question

How to generate a module in Angular?

In order to generate a module in Angular, cd to the current project directory and below command.
ng g module module_name

#7 Question

Explain Zone in Angular?

Zones are a kind of performance setting that empowers us to catch into our anachronistic tasks.
Zones in angular APIs increase the performance by executing our code exterior to the angular zone. It helps in preventing Angular from the governing unwanted alter detection assignments.

#8 Question

How to update or upgrade angular cli version

In order to upgrade angular-cli package that was installed globally in your system, you need to run following commands
npm uninstall -g angular-cli
npm cache clean or npm cache verify (if npm > 5)
npm install -g @angular/cli@latest
Instead of upgrading global version of angular-cli you can also upgrade the local version for specific project y running following commands:
rm -rf node_modules
npm uninstall --save-dev angular-cli
npm install --save-dev @angular/cli@latest
npm install

#9 Question

List some Inbuilt Pipes available in Angular

Below are the list of few Pipes available in Angular Js
  • DatePipe
  • CurrencyPipe
  • AsyncPipe
  • DecimalPipe
  • TitleCasePipe
  • JsonPipe
  • SlicePipe
  • PercentPipe
  • UpperCasePipe
  • LowerCasePipe

 

AngularJS Interview Questions

AngularJS Interview Questions

 

#1 Question

What is Angular JS?

AngularJS is a JavaScript framework that is used for making rich, extensible web applications. It runs on plain JavaScript and HTML, so you don’t need any other dependencies to make it work.AngularJS is perfect for Single Page Applications (SPA). It is basically used for binding JavaScript objects with HTML UI elements.

#2 Question

Explain the architecture of AngularJS?

AngularJS is architecture on 3 components. They are
  • The Template (View)
  • The Scope (Model)
  • The Controller (Controller)
AngularJS extends HTML attributes with Directives and binds data to HTML with Expressions.

#3 Question

What is the Template in AngularJS?

The template is the HTML portion of the angular app. It is exactly like a static HTML page, except that templates contain additional syntax which allows data to be injected in it in order to provide a customized user experience.

#4 Question

What is the scope in AngularJS?

The scope is the object that represents the “model” of your application. It contains fields that store data which is presented to the user via the template, as well as functions which can be called when the user performs certain actions such as clicking a button.
 
 

#5 Question

What is the controller in AngularJS?

The controller is a function which generally takes an empty scope object as a parameter and adds to it the fields and functions that will be later exposed to the user via the view.
 
 

#6 Question

Explain Directives in AngularJs?

AngularJS directives are extended HTML attributes with the prefix ng-
The 3 main directives of angular js are
  • ng-app:- directive is used to flag the HTML element that Angular should consider to be the root element of our application. Angular uses spinal-case for its custom attributes and camelCase for the corresponding directives which implement them.
  • ng-model:- directive allows us to bind values of HTML controls (input, select, textarea) to application data. When using ngModel, not only change in the scope reflected in the view, but changes in the view are reflected back into the scope.
  • ng-bind:- directive binds application modal data to the HTML view.

#7 Question

List some tools for testing AngularJS applications?

For testing AngularJS applications there are certain tools that you should use that will make testing much easier to set up and run.
Karma
Karma is a JavaScript command line tool that can be used to spawn a web server which loads your application’s source code and executes your tests. You can configure Karma to run against a number of browsers, which is useful for being confident that your application works on all browsers you need to support. Karma is executed on the command line and will display the results of your tests on the command line once they have run in the browser.
Karma is a NodeJS application and should be installed through NPM/YARN. Full installation instructions are available on the Karma website.
Jasmine
Jasmine is a behavior-driven development framework for JavaScript that has become the most popular choice for testing AngularJS applications. Jasmine provides functions to help with structuring your tests and also making assertions. As your tests grow, keeping them well structured and documented is vital, and Jasmine helps achieve this.
Jasmine comes with a number of matches that help you make a variety of assertions. You should read the Jasmine documentation to see what they are. To use Jasmine with Karma, we use the karma-jasmine test runner.
angular-mocks
AngularJS also provides the ngMock module, which provides mocking for your tests. This is used to inject and mock AngularJS services within unit tests. In addition, it is able to extend other modules so they are synchronous. Having tests synchronous keeps them much cleaner and easier to work with. One of the most useful parts of ngMock is $httpBackend, which lets us mock XHR requests in tests and return sample data instead.
Source:https://docs.angularjs.org/guide/unit-testing

 

Tuesday, January 15, 2019

What is AngularJs 4? Is it a good time to learn Angular Js 4?

What is AngularJs 4? Is it a good time to learn Angular Js 4?

It had been Great to learn Angular ,As it is Trending Now.
  1. Learning Angular 4 and Angular 2 are not different .
  2. Angular 4 is the extension of some features to angular 2.
About Angular 2:
  • If any one is newbie and interested to learn Angular ,then better to start with Angular 2.
  • Angular 2 is built around the concept of components, and more precisely, with the Web Components standard in mind.

 

Angular 6 Tutorial - Learn Angular 6 in this Crash Course

Angular 6 Tutorial - Learn Angular 6 in this Crash Course

 

Note: Angular 7 just released. Read or watch my Angular 7 Tutorial here!
Angular 6 has been out for a few weeks, so it's time to rehash my popular fundamentals series on Angular! This little crash course / tutorial for you if you have never worked with Angular 2+ before.
The difference between Angular 2-6 isn't massive if we're talking about the core fundamentals, but AngularJS (1.0) certainly is!
In this tutorial, I'm going to teach you by example, while discussing how things work and why they work.
Our app will fetch data from a mock API service and display it in a beautiful UI.
You're going to learn how to:
  • Install Angular 6 with the Angular CLI
  • Understand and Create Components
  • Understand and Create Services
  • Working with HTML & CSS in Angular 6
  • Working with Angular 6 Routing
  • Working with the Angular 6 HTTP Client
Let's get started!

How to Install Angular 6

The quickest and easiest way of starting an Angular 6 app is through the Angular CLI (Command Line Interface).
To install it, you're going to need either the yarn package manager or the node package manager. To check whether or not you have npm, in your console / command line, type:
> npm -v
If this goes unrecognized (and not a version number), you need to install NodeJS. Once you install NodeJS, reload your console or command line and you will have access to NPM.
Now, we can use NPM to install the Angular CLI. The Angular CLI has an official website located here.
To install it:
> npm install -g @angular/cli
If you run ng -v after installing, it will provide you with the version number. Mine happens to be 6.0.7.
Once the CLI is installed, we can now use it to start a install a brand new Angular 6 project:
> ng new ng6-proj --style=scss --routing
  • ng - This is how we call the Angular CLI.
  • new - This is one of the many commands we can issue to the CLI.
  • ng6-proj is simply the name that we're calling our project. The CLI will create a folder with this name, based on where you're running this command.
  • Optional flags - Next are two optional flags that I decided to add. First, we're telling the CLI to generate a project that has Sass enabled (by default, CSS is used if this is not specified), and then --routing is added because we want a project that has different page URL's, and adding this flag will help create a routing file for us.
To check out all of the available commands and options, run ng at the command line.
Once the CLI has generated the new project, you can hop into it:
> cd ng6-proj
If you use Visual Studio Code, you can type code . to launch the code editor. Then, to serve the project to the browser, you run:
> ng serve -o
The -o flag tells the CLI to launch your browser with the project. Now, you're able to watch your Angular 6 project as you code and it will automatically live reload. Awesome!

Angular 6 Project Structure

This is a beginner's tutorial, so we're not going to do a deep dive into every file. All that's important for you to understand are the absolute basics.
When you view the folder and file structure of your Angular 6 app, it should look something similar to this:
> e2e
> node_modules
> src
> app
...a bunch of files
...a bunch of files
You're going to spend most of your time working within the /src/app folder. This is where components and services are stored (we'll get to those shortly).
In the /src/ folder itself, you will see an index.html (the apps entry point) and a styles.css file, which is where any global CSS rulesets are placed.
The /src/assets folder is where you place any assets such as graphics.
Not present right now is a /dist/ folder, which is generated when you build the project, which we'll do later on.

The Angular 6 Module File

Before we tackle components, it's worth looking at the /src/app/app.module.ts file. Oh, and by the way, what is that .ts extension? It stands for TypeScript, and Angular 6 uses TypeScript. In short, TypeScript provides strong type checking on JavaScript.
The app.module.ts file looks like this:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
Whenever you use the CLI to generate components and services, it will automatically update this file to import and add them to the @NgModule decorator. Components are added to the declarations array, and services are added as providers. You will also find yourself adding various imports to the imports array. For instance, when we want to add animations, we will add them here.
If you're a little confused at this point, don't worry. Just understand that this is an important file that you will need to visit routinely. The CLI will take care of things for the most part, especially when generating components, but when generating services and performing some other tasks, you will need to visit this file. You'll see as a proceed.

Angular 6 Components Tutorial

A component in Angular 6 provides you with the basic building blocks of your Angular app. When we used the Angular CLI to generate our project, it created a single component.
When you use the CLI to generate components, it creates 4 files:
> src
> app
app.component.html
app.component.scss (or .css)
app.component.spec.ts
app.component.ts
  • The HTML file is the HTML template associated with that component.
  • The SCSS or CSS is the associated CSS rulesets for that component (whatever is defined in the HTML file)
  • The .spec.ts file is for testing purposes.
  • The .ts file is the actual component file, and it's where you will likely spend most of your time. It defines a number of things.
Open up the app.component.ts file:
import { Component } from '@angular/core';

@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})

export class AppComponent {
title = 'app';
}
At the top, we have our imports. You will import other components here, along with service files. We'll do that a little later.
The @Component decorator is an object with associated property / value pairs that defines important stuff associated with this component. For instance, you will see selector: 'app-root' - This provides this component with a unique identifier that is used in other areas of the app. You can also see templateUrl and styleUrls, which tells Angular where this component's HTML and CSS files are located. There are other properties that can be added here, such as animations, but we'll get to that later.
Finally, we have the logic section of the component file. This is where properties (we see that title was defined by the CLI), dependency injection and methods are defined.
Now that you understand the very basics of a component, let's create a few of our own!
In the console, run:
> ng generate component sidebar
CREATE src/app/sidebar/sidebar.component.html (26 bytes)
CREATE src/app/sidebar/sidebar.component.spec.ts (635 bytes)
CREATE src/app/sidebar/sidebar.component.ts (274 bytes)
CREATE src/app/sidebar/sidebar.component.scss (0 bytes)
UPDATE src/app/app.module.ts (479 bytes)
Here, we've told the CLI to generate a component with the name of sidebar. It outputs the 4 files it created, along with the app module file it updated!
Let's generate a few more components. Run the following commands to generate 3 more components:
> ng g c posts
> ng g c users
> ng g c details
Now, you should have a total of 5 components, 4 of which we just created ourselves. Shortly, you'll see how all of these start to work with each other and in relation to the app.

Angular 6 Templating

Let's say for instance that we want our particular app to have a sidebar with some icons. This sidebar will always be present in the app. The sidebar component is something we already generated with the CLI.
Open the src/app/app.component.html file. You will see all of the boilerplate HTML the CLI generated, and consequently, what you see in the browser for the time being. Remove all of that and paste this (or better yet, type it!):
<div id="container">
<app-sidebar></app-sidebar>

<div id="content">
<router-outlet></router-outlet>
</div>
</div>
We've wrapped everything in a container id. Then, you will notice a custom HTML element called app-sidebar. What's that?
Well, when the CLI generated the sidebar component, it made the component's selector value app-sidebar. Don't believe me? Check out /src/app/sidebar/sidebar.component.ts -- It's right there in the component decorator! That's how you embed a component inside of another component. Now, anything defined in that component's HTML, will be displayed where <app-sidebar></app-sidebar> is defined.
Another very important element is the router-outlet. This was added by the CLI when we added the --routing flag (it also generated a routing file in /src/app.
This element defines where any components defined by their routes will be displayed.
Let's head over to the /src/app/sidebar/sidebar.component.html file to define the sidebar templating:
<nav>
<ul>
<li>
<a routerLink="">
<i class="material-icons">supervised_user_circle</i>
</a>
</li>
<li>
<a routerLink="posts">
<i class="material-icons">message</i>
</a>
</li>
</ul>
</nav>
You will notice routerLink= here. Instead of href, we use routerLink to direct the user to different routes. Right now, this will not work though, we'll get to that during the routing section.
We're also going to use Material Icons, so we need to import that first.
Save this file and open up /src/index.html and add the following 2 lines between the <head> tags:
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet">


<link href="https://fonts.googleapis.com/css?family=Montserrat:300,700" rel="stylesheet">
We're importing material icons first, and then a Google web font called Montserrat.

Angular 6 CSS

Let's add some CSS rulesets to make our app look better. First, open up /src/styles.css. Any CSS/Sass defined here will apply to the HTML templating of all components, while component-specific CSS files only apply to that component's HTML template.
Add the following rulesets:
/* You can add global styles to this file, and also import other style files */
body {
margin: 0;
background: #F2F2F2;
font-family: 'Montserrat', sans-serif;
height: 100vh;
}

#container {
display: grid;
grid-template-columns: 70px auto;
height: 100%;

#content
{
padding: 30px 50px;

ul
{
list-style-type: none;
margin:0;padding:0;

li
{
background: #fff;
border-radius: 8px;
padding: 20px;
margin-bottom: 8px;

a
{
font-size: 1.5em;
text-decoration: none;
font-weight: bold;
color:#00A8FF;
}

ul {
margin-top: 20px;

li
{
padding:0;

a
{
font-size: 1em;
font-weight: 300;
}
}
}
}
}
}
}
This is a little lengthy because I don't want to keep revisiting this file. The rulesets here are applying to some elements that we haven't yet defined. Nothing too exciting is happening here though, just some standard Sass/CSS.
Next, open up the sidebar CSS file /src/app/sidebar/sidebar.component.scss:
nav {
background: #2D2E2E;
height: 100%;

ul
{
list-style-type: none;
padding: 0;
margin: 0;

li
{

a {
color: #fff;
padding: 20px;
display: block;
}

.activated {
background-color: #00a8ff;
}
}
}

}
Great. View your browser and the result should look like this:

Angular 6 Routing Tutorial

Now, let's make our 2 icons work when they're clicked. In order to do that, we need to visit the /src/app/app-routing.module.ts file.
This is what it looks like:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

const routes: Routes = [];

@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }
We need to import our components at the top, and add them to the Routes array shown on line 4 above.
To do that, add the following:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { UsersComponent } from './users/users.component';
import { DetailsComponent } from './details/details.component';
import { PostsComponent } from './posts/posts.component';

const routes: Routes = [
{
path: '',
component: UsersComponent
},
{
path: 'details/:id',
component: DetailsComponent
},
{
path: 'posts',
component: PostsComponent
},
];
We've imported our 3 components, and then defined three objects in the Routes array.
The first object specifies that the UsersComponent will be the default component that loads on the root path. We leave the path value empty forthis.
The next route is for a user details section. We've specified a wildcard named id. We'll use this to fetch that value from the router in order to retrieve the correct user details.
Then another route for a component and path called posts.
Save this file, and the browser should now show:

Awesome!

Angular 6 Services

For our users component, we want to fetch a list of users from a public API. To do that, we're going to use the Angular CLI to generate a service for us.
An Angular 6 service is useful placing code that's reusable throughout your app's different components.
In the console, type:
> ng generate service data
Open up the new service file: /src/app/data.service.ts:
import { Injectable } from '@angular/core';

@Injectable({
providedIn: 'root'
})
export class DataService {

constructor() { }
}
It looks similar to a regular component, right? You define your imports at the top, and your methods and properties in the class that's exported.
The purpose of our service file will be to communicate with an API via the Angular 6 HTTP Client.

Angular 6 HTTP Client

Angular comes with a built in HTTPClient. Let's import that at the top of our data.service.ts file:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
Next, in order to use the HttpClient, we need to create an instance of it through dependency injection within the constructor:
  constructor(private http: HttpClient) { }

getUsers() {
return this.http.get('https://jsonplaceholder.typicode.com/users')
}
We also defined a method called getUsers() which we'll call in our component shortly. It returns a list of users from a public testing API.
Before we can use the HTTPClient, we need to add as an import in our app's /src/app/app.module.ts file:
// Other imports removed for brevity

import { HttpClientModule } from '@angular/common/http'; // <-Add here

@NgModule({
declarations: [
// Removed for brevity
],
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule, // <-Add here
],
providers: [],
bootstrap: [AppComponent]
})
Great!
Next, let's open up the /src/app/users/users.component.ts file and import our service:
import { Component, OnInit } from '@angular/core';
import { DataService } from '../data.service';
import { Observable } from 'rxjs';
To display the results, we're going to use an Observable, so we're importing it here, too.
In the class, add:
export class UsersComponent implements OnInit {

users$: Object;

constructor(private data: DataService) { }

ngOnInit() {
this.data.getUsers().subscribe(
data => this.users$ = data
);
}

}
In the constructor, we're creating an instance of our service. Then, within the lifecycle hook ngOnInit() (this runs when the component loads), we're calling our getUsers() method and subscribing to it. Inside, we're binding our users$ object to the result returned by the API.
Next, open up /src/app/users/users.component.html:
<h1>Users</h1>

<ul>
<li *ngFor="let user of users$">
<a routerLink="/details/{{user.id}}">{{ user.name }}</a>

<ul>
<li>{{ user.email }}</li>
<li><a href="http://{{ user.website }}">{{ user.website }}</a></li>
</ul>
</li>
</ul>
Whenever you wish to iterate over an array or array of objects, you use the Angular directive *ngFor. We then use interpolation brackets to call upon the properties of the returned object to display them in the browser!
If you save this and refresh, you should now see a list of users and their information:

Fetching More Data from the API

Let's revisit the service file /src/app/data.service.ts and add the following methods:
  getUser(userId) {
return this.http.get('https://jsonplaceholder.typicode.com/users/'+userId)
}

getPosts() {
return this.http.get('https://jsonplaceholder.typicode.com/posts')
}
The getUser() method will provide us with a single user's information, which will accept a userId as a parameter.
getPosts() will fetch some fictional posts for us to get more muscle memory with this process of communicating with services.
Visit /src/app/details/details.component.ts:
import { Component, OnInit } from '@angular/core';
import { DataService } from '../data.service';
import { Observable } from 'rxjs';
import { ActivatedRoute } from "@angular/router";

@Component({
selector: 'app-details',
templateUrl: './details.component.html',
styleUrls: ['./details.component.scss']
})
export class DetailsComponent implements OnInit {

user$: Object;

constructor(private route: ActivatedRoute, private data: DataService) {
this.route.params.subscribe( params => this.user$ = params.id );
}

ngOnInit() {
this.data.getUser(this.user$).subscribe(
data => this.user$ = data
);
}

}
This, as you see, is very similar to our users component. The only difference comes when we import ActivatedRoute and call it within the constructor.
The purpose of this code allows us to grab the id router parameter that we defined in the app's routing file earlier. This will give us access to the user ID and then pass it to the getUser() method that we defined.
Open up the details.component.html and specify:
<h1>{{ user$.name }}</h1>

<ul>
<li><strong>Username:</strong> {{ user$.username }}</li>
<li><strong>Email:</strong> {{ user$.email }}</li>
<li><strong>Phone:</strong> {{ user$.phone }}</li>
</ul>
Save it, and click on one of the user's names:

Awesome!
For more muscle memory, let's repeat this process for the /src/app/posts/posts.component.ts file:
import { Component, OnInit } from '@angular/core';
import { DataService } from '../data.service';
import { Observable } from 'rxjs';

@Component({
selector: 'app-posts',
templateUrl: './posts.component.html',
styleUrls: ['./posts.component.scss']
})
export class PostsComponent implements OnInit {
posts$: Object;

constructor(private data: DataService) { }

ngOnInit() {
this.data.getPosts().subscribe(
data => this.posts$ = data
);
}

}
And the posts.component.html file:
<h1>Posts</h1>

<ul>
<li *ngFor="let post of posts$">
<a routerLink="">{{ post.title }}</a>

<p>{{ post.body }}</p>
</li>
</ul>
Save it, and click on the posts icon in the sidebar:

Great!

Angular 6 Class Binding

It would be nice to indicate which page a user is currently on in the left sidebar, perhaps by adding a class to the icon that will make its' background blue? Sure!
Visit the /src/app/sidebar/sidebar.component.ts file and add the following:
import { Component, OnInit } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';

export class SidebarComponent implements OnInit {

currentUrl: string;

constructor(private router: Router) {
router.events.subscribe((_: NavigationEnd) => this.currentUrl = _.url);
}

ngOnInit() {}

}
We're importing the Router and NavigationEnd, then defining a string property currentUrl. Then, we create an instance of the Router in order to subscribe to router.events. It will provide us with a string, which is the current router path.
Open the sidebar.component.html file and update it to match:
<nav>
<ul>
<li>
<a routerLink="" [class.activated]="currentUrl == '/'">
<i class="material-icons">supervised_user_circle</i>
</a>
</li>
<li>
<a routerLink="posts" [class.activated]="currentUrl == '/posts'">
<i class="material-icons">message</i>
</a>
</li>
</ul>
</nav>
Class binding works by binding [class.csspropertyname] to a template expression. It will only add the .activated CSS ruleset (defined in styles.scss) if our currentUrl is equal to either / or /posts.
Save it. The result should now look like this:

Try clicking on the other icon!

Angular 6 Animation Tutorial

Let's say for instance that we want our list of user's on the user's page to fade in when the component loads. We can use Angular's powerful animation library to help us achieve this.
In order to gain access to the animation library, we have to first install it from the console:
> npm install @angular/animations@latest --save
Then, we add it to the imports of /src/app/app.module.ts:
// Other imports removed for brevity
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';

@NgModule({
...
imports: [
// other modules removed for brevity
BrowserAnimationsModule
],
})
Next, open up /src/app/users/users.component.ts and add the following to the top imports:
import { trigger,style,transition,animate,keyframes,query,stagger } from '@angular/animations';
Then, in the component decorator, add the following animations property with the associated code:
@Component({
selector: 'app-users',
templateUrl: './users.component.html',
styleUrls: ['./users.component.scss'],

// Add this:
animations: [
trigger('listStagger', [
transition('* <=> *', [
query(
':enter',
[
style({ opacity: 0, transform: 'translateY(-15px)' }),
stagger(
'50ms',
animate(
'550ms ease-out',
style({ opacity: 1, transform: 'translateY(0px)' })
)
)
],
{ optional: true }
),
query(':leave', animate('50ms', style({ opacity: 0 })), {
optional: true
})
])
])
]
})
Whew, a lot happening here!
  • We start off by defining an animation by giving it a trigger with a name listStagger.
  • Next, we use transition to define when the animations will take place, from one animation state to the other. A wildcard is used to say from any state to any state, in this case.
  • Then, we use query to say that on :enter, we apply an initial style that's hidden and moved on the Y axis by -15px, and make a stagger animation for each sequential element. 
  • At the end, we define an optional :leave animation.
To make this work, visit the /src/app/users/users.component.html file and reference the animation trigger:
<ul [@listStagger]="users$">
Save it, and click on the users icon. You will notice that the list animates in!
There's a lot more to Angular animation, so this is just one potential use case.

 

lEARNING: SQL | WHERE Clause

SQL | WHERE Clause WHERE keyword is used for fetching filtered data in a result set. It is used to fetch data accord...