Friday 25 November 2022

Angular #5 with JSON

Ex 10

Angular with MongoDB integration

Ref : https://www.freakyjolly.com/angular-12-how-to-load-json-data-from-assets-folder/

Step 1

Create a new app by 

ng new json-demo

cd json-demo

code .  to open Visual Studio Code Editor

open app.component.ts file

add

import EmployeesJson from '../assets/employee.json';

and modify AppComponent class by

interface EMPLOYEE {
  ids: number;
  name: string;
}

export class AppComponent {
  title = 'Demo for angular-json interaction';
  Employees: EMPLOYEE[] = EmployeesJson;

  constructor(){
    console.log(this.Employees);
  }

Step 2 

Create JSON File: employees.json  in assets Folder
[
    { "ids": 102, "name": "Dr. Nice" },
    { "ids": 103, "name": "Bombasto" },
    { "ids": 104, "name": "Celeritas" },
    { "ids": 105, "name": "Magneta" },
    { "ids": 106, "name": "RubberMan" },
    { "ids": 107, "name": "Dynama" },
    { "ids": 108, "name": "Dr. IQ" },
    { "ids": 109, "name": "Magma" },
    { "ids": 200, "name": "Tornado" }
  ]

Step 3 
In app folder, create a file name as json-typings.d.ts +  add the following contents and save.
declare module "*.json" {
    const value: any;
    export default value;
    }
Step 4 
Modify file: app.component.html  in app folder as below:
<div>
  <table class="table">
    <thead>
        <tr>
          <th>Ids</th>
          <th>Name</th>
        </tr>
    </thead>
    <tbody>
      <tr *ngFor="let employee of Employees">
        <th>{{ employee.ids }}</th>
        <td>{{ employee.name }}</td>
      </tr>
    </tbody>
  </table>
</div>


Step 5 
Modify file: app.component.html  in app folder as below:
 <div class="container mt-5">
  <h1>{{title}}</h1>
  <div>
  <table class="table">
    <thead>
        <tr>
          <th>Ids</th>
          <th>Name</th>
        </tr>
    </thead>
    <br>
    <tbody>
      <tr *ngFor="let employee of Employees">
        <th scope="row">{{ employee.ids }}</th>
        <td style="color: #ff00ff">{{ employee.name }}</td>
      </tr>
    </tbody>
  </table>
</div>
Step 6: 

Install bootstrap by this command in New Terminal of VS code Editor

npm install bootstrap --save

After bootstrap installation: Open angular.json file.
update "styles.css" file at app  root with 

body {background-color: coral;}

In terminal type:

ng serve -o  

Check the browser window will appear similar to this:




Happy ☺☺☺☺Angular  App Development!!!



 

Thursday 24 November 2022

Angular #4 Routing

Navigation in Angular is done by Routing

Please follow these steps in command prompt:

1. ng new router-example   Select y for Routing and CSS for stylesheet.

2. cd  router example

3. ng g c student

4. ng g c subject

5. code . (or) Open the folder router-example manually 

6. In VS code editor, open the app.module.ts file.

7.

import { RouterModule } from '@angular/router';

Locate @NgModule() section replace imports array with the following and save: 

 imports: [
    BrowserModule,
    RouterModule.forRoot([
      {path: 'student', component: StudentComponent},
      {path: 'subject', component: SubjectComponent},
    ]),
  ],

8. Open file app.component.html. add and save

Delete the old contents. add  and save:

<app-student></app-student>

<app-subject></app-subject>

open New Terminal Window and type 

ng serve

open in browser http://localhost:4200

:to check the app is working .

9. Open file app.component.html. add the following and save

<nav>
  <a class="button" routerLink="/student">Student List</a> |
  <a class="button" routerLink="/subject">Subject List</a>
 </nav>
<router-outlet> </router-outlet>

Check the Browser output to see as navbuttons.

10. open the app.component.css. Add the following and save:

.button {
    box-shadow: inset 0 1px 0 0 #ffffff;
    background: #ffffff linear-gradient(to bottom, #ffffff 5%, #f6f6f6 100%);
    border-radius: 6px;
    border: 1px solid #dcdcdc;
    display: inline-block;
    cursor: pointer;
    color: #666666;
    font-family: Arial, sans-serif;
    font-size: 15px;
    font-weight: bold;
    padding: 6px 24px;
    text-decoration: none;
    text-shadow: 0 1px 0 #ffffff;
    outline: 0;
}

.activebutton {
    box-shadow: inset 0 1px 0 0 #dcecfb;
    background: #bddbfa linear-gradient(to bottom, #bddbfa 5%, #80b5ea 100%);
    border: 1px solid #84bbf3;
    color: #ffffff;
    text-shadow: 0 1px 0 #528ecc;
}

10. Now Check in Browser window similar to the window as shown.

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

11. Adding some data in component to display while we navigate:

 Open subject.component.ts file and add/modify as follows the class SubjectComponent

 subjects = [
    { id: 12, name: 'Networks' },
    { id: 13, name: 'C' },
    { id: 14, name: 'C++' },
    { id: 15, name: 'Angular' },
    { id: 16, name: 'React' },
    { id: 17, name: 'Java' },
    { id: 18, name: 'Python' },
    { id: 19, name: 'HTML' },
    { id: 20, name: 'CSS' }
 
   ];

12. Add the following contents to student.component.html file:
<div *ngFor="let s of subjects">
    <div style="color: #0000ff">
        {{s.id}}:  {{s.name}}:
    </div>
</div>


13. Open subject.component.ts file and add/modify as follows the class SubjectComponent and save

 students = [
    { id: 102, name: 'Dr. Nice' },
    { id: 103, name: 'Bombasto' },
    { id: 104, name: 'Celeritas' },
    { id: 105, name: 'Magneta' },
    { id: 106, name: 'RubberMan' },
    { id: 107, name: 'Dynama' },
    { id: 108, name: 'Dr. IQ' },
    { id: 109, name: 'Magma' },
    { id: 200, name: 'Tornado' }
  ];

12. Add the following contents to subject.component.html file and save:
<div *ngFor="let s of students">
    <div style="color: #0000ff">
        {{s.id}}:  {{s.name}}:
    </div>
</div>


13. Check these output in browser window by typing ng server in terminal http://localhost:4200 in browser

Happy Learning Angular !!!💁💁


Exercise 

1. Modify file app.component.css with the following contents 

.button {
    box-shadow: inset 0 1px 0 0 #ffffff;
    background: #ffffff linear-gradient(to bottom, #ffffff 5%, #f6f6f6 100%);
    border-radius: 6px;
    border: 1px solid #dcdcdc;
    display: inline-block;
    cursor: pointer;
    color: #666666;
    font-family: Arial, sans-serif;
    font-size: 15px;
    font-weight: bold;
    padding: 6px 24px;
    text-decoration: none;
    text-shadow: 0 1px 0 #ffffff;
    outline: 0;
}

.activebutton {
    box-shadow: inset 0 1px 0 0 #dcecfb;
    background: #bddbfa linear-gradient(to bottom, #bddbfa 5%, #80b5ea 100%);
    border: 1px solid #84bbf3;
    color: #ffffff;
    text-shadow: 0 1px 0 #528ecc;
}


2. Modify the first <a> tag in app.component.html as follows:

<a class="button"
     routerLink="/student"
     routerLinkActive="activebutton"
     ariaCurrentWhenActive="page">Student List</a> |
 

See the browser output.

Monday 21 November 2022

Angular 3 Structural Directives(+/- components in HTML View)

EX 5 : 

*ngFor Directive

Create a new Angular Application in Visual Studio IDE Terminal

ng new EX5

Open folder EX5 and open src\app\app.component.html    file and add the following contents and save.

<div *ngFor = "let i of [1,3,5,7,9,11,12,14,15]">
  <li>No is : {{i}}<br></li>
</div>

run 

ng serve in Terminal. 

Once you get compiled successfully message, 

  1. Open http://localhost:4200 in any browser to check the following o/p:  
  • No is : 1
  • No is : 3
  • No is : 5
  • No is : 7
  • No is : 9
  • No is : 11
  • No is : 12
  • No is : 14
  • No is : 15   
  • -----------------------------------------------------------------------------------------------------------------------------

    EX 6 

    *ngIf Directive

    Open file src\app\app.component.ts file and add the displayButton object as shown below:

    export class AppComponent {
        displayButton: boolean = true;
    }


    Open  src\app\app.component.html    file and add the following contents and save.

    <div>
      <div *ngIf="displayButton">
         Message will disappear  when you click this button
            <button class="btn btn-sucess" (click)="showHide();">Click Me to Hide</button>
      </div>

    run 

    ng serve in Terminal. 

    Once you get compiled successfully message, Open http://localhost:4200 in any browser to check the following o/p initially:  

    Message will disappear when you click the button. with Click me to Hide Button. Once you click the button the browser screen will be blank.

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

    EX 7

    ngStyle Directive

    Open  src\app\app.component.html    file and add the following contents and save.

    <!-- //ngSTyle : changes the look and Behaviour of Web Page -->
    <div *ngFor = "let i of [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]">
        <div *ngIf = "(i%2 != 0)" [ngStyle]="{'background-color':'green'}">
            <li><button>{{i}}</button></li>
        </div>
        <div *ngIf = "(i%2 === 0)" [ngStyle]="{'background-color':'red'}">
            <li><button>{{i}}</button></li>
        </div>
    </div>

    run by ng serve in Terminal. 

    Once you get compiled successfully message, Open http://localhost:4200 in any browser to check the following o/p:  

    You will get screen like this


    EX8

    Pipes

    Open file src\app\app.component.ts file and add the displayButton object as shown below:

    export class AppComponent {
        textPipe = 'lower case to be converted to uppercase';
    }

    Open  src\app\app.component.html    file and add the following contents and save.

    <div>
      Original Text:&nbsp;{{textPipe}}<br>
      To lowercase :<span style="color:'green'">&nbsp;{{textPipe |  lowercase}}</span>---> all Lowerase<br>
      To uppercase :<span style="color:'blue'">&nbsp;{{textPipe |  uppercase}}</span>---> all uppercase<br>
      Slicing:<span style="color:'red'">{{textPipe | slice:0:5}}</span>--->First 5 charecters of the original text<br>
    </div>

    run ng serve in Terminal. 

    Once you get compiled successfully message, Open http://localhost:4200 in any browser to check the following o/p initially:  

    In browser:

            Original Text: First Pipe
            To lowercase : first pipe---> all Lowerase
            To uppercase : FIRST PIPE---> all uppercase
            Slicing:First--->First 5 charecters of the original text

    Happy Learning Angular! ☺☺☺














    Angular #2 Data Binding {{}} , [ ], ( ), [()]

    Ex 1.

    One Way Binding {{}}

    In Visual Studio, Terminal 

    create a project using 

     ng new ex1

    Ans N for Would you like to Add Angular Routing ?

    Choose CSS for Which Style sheet format you like to use?

    Will install packages(npm).

    Open folder ex1

    Expand src directory to see app, assets, environments.. directories.

    In app directory, open app.component.html files. Delete all the contents.

    add the following and save.

    <h1>{{title}}</h1>

    Invoke by 

    ng serve to run the server in Terminal Window. 

    Open any browser and go to http://localhost:/4200

    will display the title ex1 in browser

     Ex 2.

    Add user defined object inputData

    Add  the above USO in app.component.ts file AppCompenet class by 

    inputData = 'User Defined Data in Class';

    In app directory, open app.component.html files. 

    add the following and save.

    <p style="color: rgb(128, 0, 28);"><b>{{inputData}}</b></p>

    Check in browser.


    Ex  3.

    Add a new Component 'Container'In terminal 

    In Terminal Window, command prompt

    ng generate component container

    to create a new componont. Will create four new files and one update one file.

    PS F:\AngularCourse\ex1> ng generate component container
    CREATE src/app/container/container.component.html (24 bytes)
    CREATE src/app/container/container.component.spec.ts (620 bytes)
    CREATE src/app/container/container.component.ts (287 bytes)
    CREATE src/app/container/container.component.css (0 bytes)
    UPDATE src/app/app.module.ts (408 bytes)

    Now check the container.component.html file.

    Add the following contents inside app.compoent.html

    <app-container></app-container>

    Delete the contents. Add the following

    <h1>Header Comes here</h1>
    <h3>Nav Bar comes here</h3>
    <h5>Content  comes here</h5>

    Now invoke webpack by 

    ng serve

    command inside the terminal prompt to check the browser contents. 

    Ex 4.

    Evet data binding 

    add the following contents  in container.component.html file.

    <div>
        <Label> First Name : </Label>
        <input type="text">
        <button (click) = "onClick()">Clik Me</button>
    </div>

     in src\app\container\container.component.ts file, add the following 

    Inside ContainerComponent class after ngOnInit(): void{}  and save

    onClick(){
        alert('Some body kicked the Button');
      }

    Now invoke webpack by ng serve and check http://localhost:4200 in browser. Click the button to see alert box.


    Ex4: 

    Two way Binding [(ngModule)]y

    create a new project using 

    ng new ex4


    Add the following contents  in container.component.html file.

    <div>
        <Label> First Name : </Label>
        <input type="text" [(ngModel)] = "inputData"> <br><br>
        Entered Choice is  : {{inputData}}
    </div>

    Open app.component.ts File , add inside the class AppComponent  and save file.

    inputData = 'Two way Binding Example';

    Add the following in app.module.ts file import section and save.

    import { FormsModule } from '@angular/forms';

    Register  FormsModule   as shown below:


    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        AppRoutingModule,
        FormsModule
      ],
      providers: [],
      bootstrap: [AppComponent]
    })

    run ng serve in terminal. Check in the opened browser http://localhost:4200.

    Whatever you typed will be displayed immediately next to  Entered Choice is  :



    Thursday 17 November 2022

    Angular #1 Installation

    Why named it as Angular. b'cos it is written between < > !

     Angular is typescript for building client applications framework.

    Angular is easier, clean loosely coupled architecture and more testable and reusable.

    Architecture: (FE+BE)

    Front End  (UI): Client (Browser) use HTML CSS( Templates) , Type Script (Extended Java Script), angular

    Back End  (Data Processing):  Data + API (Application Programming Interface) + Business Logic

    Simply, Angular makes life easier!

    Angular Version is known as AngularJS. Later versions are known As Angular V x. (latest is Angular 14.0)

    Difference between AngularJS and Angular

    Architecture :      MVC Model vs  Components and Directives

    Language     :      Java Script vs Type Script

    Mobile          :    Not Mobile friendly vs Mobile Friendly

    Expression Syntax : {{}} vs () []

    Dependency Injection : Not used vs Hierarchical DI is used

    Routing     :     @routProvider  vs @Route configuration

    Code         :      Unmanageable vs Structured


    1. First Angular Project:

    Download latest stable version node.js from nodejs.org depending on your platform (Windows-32/64/Mac/Linux) (in my case downloaded windows 64 bit node-v18.12.1-x64.msi on 17.11.2022). Install as Administrator. Check  in command prompt by this command

                node --version

    Download Angular CLI (Command Line Interface) tool by this command 

                npm install -g @angular/cli

    Check in command prompt by this command 

                ng version

    Create angular project in command prompt:

                ng new hello-universe  where hello-universe is angular project name.
                Will ask some questions like: 
                 Ans 'N' for Would you like to add Angular routing? y/n -
                 Select 'CSS' for ? Which stylesheet format would you like to use? 
                will take some time to create necessary files for the angular project

     Download beautiful cross platform code editor: Visual Studio  from https://code.visualstudio.com/download to get VSCodeUserSetup.exe and install as Administrator. 

    Go to hello-universe directory. type the following command to check the visual code editor

                code .

     You can observe the Visual studio IDE opened with HELLO-UNIVERSE project. Now our first Angular Project is ready. We can run by this in command prompt 

                ng serve

    will build  and display message Compiled successfully at the end.

    Now open the browser and type in the address bar

               localhost:4200

    Your first application will show screen like this 


    Great My friend, You have done it!






            

        


     











    Tuesday 12 July 2022

    #0 Intro to Data Analysis

     Two Words

    Data & Analysis

    Data : oil, Electricity,  everywhere, every time, even now.

    Analysis : Answer how and Why ?

    Analysis :

    Data analysis is the process of collecting, modeling, and analyzing data to extract insights that support decision-making. There are several methods and techniques to perform analysis depending on the industry and the aim of the investigation


    Why Is Data Analysis Important?

    Informed decision-making: 

    Reduce costs| Increase Profits

    Target Customers Better


    DA is a Process

    Identify-Collect-Clean-Analyze-Interpret or Infer- Act

    (ICCAIA)


    Types of DA

    1.Descriptive: What ?-Data to Valuable Insights

    2.Exploratory: How  ?-To generate Hypothesis to solve specific 3.Problems

    4.Diagnostic : Why ? - To tackle and to cure 

    5.Predictive  : What if ? - Future Projection

    6.Prescriptive : IF-?.Then-This : 


    Top DA Methods

    1. Cluster Analysis: Similar elements - Grouping Data 

    2. Cohort Analysis : Historical data to examine and compare -Google Analytics:

    3. Regression Analysis - y=mx+c

    4. Factor Analysis : Dimension Reduction

    5. Neural Networks : Mimic Human Brain to find solutions

    6. Data Mining: Identify patterns, Dependencies, realations, Trends

    7. Text Analysis : Actional Insights with Relevant Data

    8. TimeSeries Analysis : Data Collected over a specified period of time.

    9. Decison Trees: To support smart and strategic Decisions

    10. Conjoint Analysis : How individuals value different attributes of a product or Service



    Top 17 Data Analysis Techniques:


    Collaborate your needs

    Establish your questions

    Data democratization

    Think of data governance 

    Clean your data

    Set your KPIs

    Omit useless data

    Build a data management roadmap

    Integrate technology

    Answer your questions

    Visualize your data

    Interpretation of data

    Consider autonomous technology

    Build a narrative

    Share the load

    Data Analysis tools

    Refine your process constantly 


    Quality Criteria For Data Analysis 

    Internal Validity

    External Validity

    Reliability

    Objectivity



    Application of DA:


    Academics: Universities and academic institutions can perform data analysis to measure student performance and gather insights on how certain behaviors can further improve education.


    Human Resources: Organizations can use data analysis to offer a great experience to their employees and ensure an excellent work environment. They can also utilize the data to find out the best resources whose skill set matches the organizational goals



    Communication is very Important


    Qualitative


    Stephen Few - 8 Types of Quantitative Messages out of DA:

    1. Time Series : Line Chart

    2. Ranking : Bar Chart

    3. Part-to-Whole : Pie Chart

    4. Deviation: Bar Comparison : Actual Vs Variation

    5. Frequency Distribuition : Histogram

    6. Correlation: Scatter Plot 

    7. Nominal Comparison : bar Chart

    8. Geographical : Cartogram


    Quantitative

    mean, median, mode, Standard deviation, chi-square, eigen vector



    Free software for data analysis


    Notable free software for data analysis include:


    DevInfo – A database system endorsed by the United Nations Development Group for monitoring and analyzing human development.[149]

    ELKI – Data mining framework in Java with data mining oriented visualization functions.

    KNIME – The Konstanz Information Miner, a user friendly and comprehensive data analytics framework.

    Orange – A visual programming tool featuring interactive data visualization and methods for statistical data analysis, data mining, and machine learning.

    Pandas – Python library for data analysis.

    PAW – FORTRAN/C data analysis framework developed at CERN.

    R – A programming language and software environment for statistical computing and graphics.[150]

    ROOT – C++ data analysis framework developed at CERN.

    SciPy – Python library for data analysis.

    Julia - A programming language well-suited for numerical analysis and computational science.


    Making Prompts for Profile Web Site

      Prompt: Can you create prompt to craft better draft in a given topic. Response: Sure! Could you please specify the topic for which you...