Monday, April 27, 2020

Angular Material Form Controls Select (mat-select) Example


app.component.ts

<h2>Basic mat-select Example</h2>
<mat-form-field>
  <mat-label>Your student</mat-label>
  <mat-select>
    <mat-option *ngFor="let student of students" [value]="student.name">
      {{student.name}}
    </mat-option>
  </mat-select>
</mat-form-field>


app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModuleReactiveFormsModule } from '@angular/forms';
import { MatSelectModule } from '@angular/material/select';
import { MatFormFieldModule } from '@angular/material/form-field';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    FormsModule,
  ReactiveFormsModule,
  MatSelectModule,
  MatFormFieldModule
    
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

app.component.ts


import {Componentfrom '@angular/core';
import {FormControlfrom '@angular/forms';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent{
  studentsany[] = [
    { name: 'Michael' },
    { name: 'John'},
    { name: 'David' },
    { name: 'Robert' },
    {name:'james'},
    
];  
  }

Saturday, January 11, 2020

Table Dropdown Filter with jQuery

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>

  <script type="text/javascript">
    $(document).ready(function() {
    function addRemoveClass(theRows) {
        theRows.removeClass("odd even");
        theRows.filter(":odd").addClass("odd");
        theRows.filter(":even").addClass("even");
    }
    var rows = $("table#myTable tr:not(:first-child)");
    addRemoveClass(rows);
    $("#dropdownField").on("change", function() {
        var selected = this.value;
        if (selected != "All") {
            rows.filter("[position=" + selected + "]").show();
            rows.not("[position=" + selected + "]").hide();
            var visibleRows = rows.filter("[position=" + selected + "]");
            addRemoveClass(visibleRows);
        } else {
            rows.show();
           addRemoveClass(rows);
        }
    });
});

</script>

app.component.html

<div class="dropdownList">
  Filter By Name
  <select id="dropdownField">
      <option value="All" selected>All</option>
      <option value="Student">Student</option>
      <option value="Assistant">Assistant</option>
   
  </select>

</div>
<table id="myTable">
  <tr id="headerRow">
      <td>First Name</td>
       <td>Age</td>
      <td>Position</td>
  </tr>

  <tr position="Student">
      <td>John</td>
       <td>25</td>
      <td>Student</td>
  </tr>

 
  <tr position="Professor">
      <td>Olivia</td>
       <td>25</td>
      <td>Professor</td>
  </tr>

  <tr position="Professor">
      <td>Ava</td>
       <td>21</td>
      <td>Professor</td>
  </tr>

  <tr position="Student">
      <td>Sophia</td>
       <td>20</td>
      <td>Student</td>
  </tr>

</table>

styles.css
body{
  font-family: Arial, Helvetica, sans-serif; font-size:28px;
}
#myTable{
  width:100%;
  border-collapse:collapse;
  }
  #headerRow {
    background: #2700ff;
    color: white;
    font-weight: bold;
}
  #myTable td{
  padding:5px;
  border:1px solid #00a5e4;
  text-align:left;
  }
  .dropdownList {
  padding-bottom:10px;
  font-weight:bold;
  }
  #dropdownField {
    border-radius: 5px;
    border: 1px solid #ccc;
    font-size: 16px;
    height: 30px;
    width: 200px;
    color: white;
    background-color: #2700ff;
}
.odd {
  background: #cceaff;
}
.even {
  background: #99e3ff;
}


app.component.ts
<div class="icon-bar">
<a href="#" class="facebook"><i class="fa fa-facebook"></i></a> 
 <a href="#" class="twitter"><i class="fa fa-twitter"></i></a> 
 <a href="#" class="linkedin"><i class="fa fa-linkedin"></i></a>
</div>
    <header><h3><span style="color: yellow; font-size: 65px;">Angular Font Awesome</span> Sticky Social Side Bar</h3></header>

    <div class="content">
   <p>The Sticky social bar will stick to the screen when you scroll.</p>
    <p>
    It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
   </p>
   <p>
    It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
   </p>
  <p>
    It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
   </p>
   <p>
    It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
   </p>
  <p>
    It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
   </p>
  <p>
    It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
   </p>
</div>

styles.css
body {

  margin: 0;

  height: 1800px;

  background: #000;

  color: #FFF;

}

.icon-bar {
  position: fixed;
  top: 50%;
  -webkit-transform: translateY(-50%);
  -ms-transform: translateY(-50%);
  transform: translateY(-50%);
}
header{
  position: fixed; width: 100%;
  top: -52px;
}
header h3 {
  background: #0400ff;
  padding: 18px;
  font-size: 47px;
  color: #00ffe0;
}
.icon-bar a {
  display: block;
  text-align: center;
  padding: 16px;
  transition: all 0.3s ease;
  color: white;
  font-size:50px;
}
.icon-bar a:hover {
  background-color: #ff6b01;
}
.facebook {
  background:#0541be;
  color: white;
}
.twitter {
  background:#0091ff;
  color: white;
}
.linkedin {
  background:#005780;
  color: white;
  font-size: 37px;
}
.content {
  font-size: 30px;
  width: 80%;
  text-align: justify;
  float: right;
  margin-top: 20px;
  right: 8%!important;
  font-family: sans-serif;
  z-index: -111;
  position: relative;
}
Install Packages
npm i angular-font-awesome

angular.cli.json
  "styles": [
        "styles.css",
        "../node_modules/font-awesome/css/font-awesome.css"

      ],



Thursday, January 9, 2020

Angular 8+ with ngx-charts





app.component.html
----------------------------------------------
    <div style="display: inline-block">
    <ngx-charts-area-chart
      [view]="view"
      [scheme]="colorScheme"
      [results]="multi"
      [gradient]="gradient"
      [xAxis]="showXAxis"
      [yAxis]="showYAxis"
      [legend]="showLegend"
      [showXAxisLabel]="showXAxisLabel"
      [showYAxisLabel]="showYAxisLabel"
      [xAxisLabel]="xAxisLabel"
      [yAxisLabel]="yAxisLabel"
      [autoScale]="autoScale"
      (select)="onSelect($event)">
    </ngx-charts-area-chart>
    </div>

app.component.ts
----------------------------------------------
import { Component } from '@angular/core';
@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

public multi = [
  {
    "name": "India",
    "series": [
      {
        "name": "2009",
        "value": 7500000
      },
      {
        "name": "2010",
        "value": 8948000
      }
    ]
  },

  {
    "name": "USA",
    "series": [
      {
        "name": "2009",
        "value": 7874000
      },
      {
        "name": "2010",
        "value": 8276000
      }
    ]
  },
  {
    "name": "Singapur",
    "series": [
      {
        "name": "2009",
        "value": 5004002
      },
      {
        "name": "2010",
        "value": 5804000
      }
    ]
  }
];
 view: any[] = [700, 400];
  showXAxis = true;
  showYAxis = true;
  gradient = false;
  showLegend = true;
  showXAxisLabel = true;
  xAxisLabel = 'Number';
  showYAxisLabel = true;
  yAxisLabel = 'data';
  timeline = true;
   colorScheme = {
    domain: ['#E91E63', '#CDDC39', '#3F51B5', '#AAAAAA']
  };}

app.module.ts
-----------------------------------------------------------
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { NgxChartsModule } from "@swimlane/ngx-charts";
import { AppComponent } from './app.component';

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


Install

To use ngx-charts in your project install it via npm:
npm i @swimlane/ngx-charts --save

Fetching JSON data from REST APIs

data.json---------------------------------- [     {     "userId" : 1 ,     "id" : 1 ,     "title" : "sunt...