Thursday 19 January 2017

jquery-BackToTopscript

<div class="take-me-top" id="back-to-top">
        <p>Back To Top</p>
    </div>


    <script>
    if ($('#back-to-top').length) {
        var scrollTrigger = 100, // px
            backToTop = function() {
                var scrollTop = $(window).scrollTop();
                if (scrollTop > scrollTrigger) {
                    $('#back-to-top').addClass('show');
                } else {
                    $('#back-to-top').removeClass('show');
                }
            };
        backToTop();
        $(window).on('scroll', function() {
            backToTop();
        });
        $('#back-to-top').on('click', function(e) {
            e.preventDefault();
            $('html,body').animate({
                scrollTop: 0
            }, 700);
        });
    }
    </script>

Hide scrollbar - Do scrollable in CSS - Overflow scroll

Hide scroll bar, but still being able to scroll
------------------------------------------------

#element::-webkit-scrollbar {
   height: 42px;
   overflow: hidden;
 

   display: none;
}

NG2- Input and Output - Event Emitter - Sample

component1.html:
---------------
(click)="mobileMenuClick()"


component1.component.ts
-----------------------

import { component, Input, Output, EventEmitter } from '@angular/core'

 @Output() mobileMenu = new EventEmitter <boolean>() ;


mobileMenuClick(){
  console.log('clickedd.........');
  this.isToggleVisible = !this.isToggleVisible;
  debugger;
  this.mobileMenu.emit(this.isToggleVisible);

}

component2.componet.ts -> html and component
--------------------------

import {Component, ViewContainerRef,ViewEncapsulation,OnInit, OnChanges} from '@angular/core';
<ba-page-top (mobileMenu)="moileMenuClicked($event)"></ba-page-top>

<ba-sidebar menuItems="systemMain" [pageId]="pageNumber" [mobileMenuClicked]="mobileMenuClick"></ba-sidebar> // Pass to another component

 moileMenuClicked(e){
    console.log("System Component -- mobliemenuclicked()" + e);
    //this.mobileMenuClick = clickFlag;
  }

import {Component, ViewContainerRef,ViewEncapsulation,OnInit, OnChanges} from '@angular/core';
import { Overlay } from 'angular2-modal';
import { Modal } from 'angular2-modal/plugins/bootstrap';

import {ActivatedRoute} from '@angular/router'

@Component({
  selector: 'system',
  encapsulation: ViewEncapsulation.None,
  styles: [require('./system.scss')],
  template: `
    <ba-page-top (mobileMenu)="moileMenuClicked($event)"></ba-page-top>
    <div class="row systemMainPanel">
      <div class="LeftMenu">
      <ba-sidebar menuItems="systemMain" [pageId]="pageNumber" [mobileMenuClicked]="mobileMenuClick"></ba-sidebar>
      </div>
      <div class="al-content">
       <router-outlet></router-outlet>
      </div>
    </div>
 
<ba-back-top position="200"></ba-back-top>
    `
})
export class SystemComponent implements OnInit {

  private pageNumber: any;
  mobileMenuClick:boolean;

  constructor(private route:ActivatedRoute) {
  }

  ngOnInit(){
      let id = this.route.params.subscribe(params => {
        this.pageNumber = Number.parseInt(params['id']);
      });
      console.log(this.pageNumber)
  }
  moileMenuClicked(clickFlag){
    console.log("System Component -- mobliemenuclicked()" + clickFlag);
    this.mobileMenuClick = clickFlag;
  }
}

NG2-If-else-ngClass-apply

component1.html
-----------------
<div [ngClass]="{'n-dropdown-menu--active': isActive, 'n-dropdown-menu': true}">

<a (click)="isActive = !isActive">Click</a>
</div>

component1.component.ts
-----------------------
import {component} from 'angular@/core';

@componet{

}
export class classname{

isActive =false;

}

component1.css
--------------
n-dropdown-menu--active{

background : red;
}
n-dropdown-menu{

background: Green;
}

By default the dropdown background color is green. Once click,
 it will be toogle the color as red and green

NG2 -select-dropdown-checkobc-radio Model 2 Template and Template 2 Model

Select - Dropdown -option
-------------------------

<div id="selectDiv">
          <select id="dropdown" (change)="getdays()">
     <option  *ngFor='let data of day_list'>{{data.days}}</option>
    </select>

componet.ts
------------

getdays(e) {

var inputValue: any = (<HTMLInputElement>document.getElementById('dropdown'));
let index = inputValue.selectedIndex;
this.alertService.getAlertData(this.day_list[index].id, this.url).subscribe(
 (data: any) => {
if (data.success) {
}
}


Checkbox - selected list to show
---------------------------------

input type="checkbox" [(checked)]="Checkvalue.Regular" id="Regular" name="Regular" (change)="onclickcheckbox($event)">

<tr *ngFor="let rowdata of AsupTableRows | filter:{ option:filtered}>

 componet.ts
 -----------
 public Checkvalue:Object={
"Regular":true,
"Others":true
};
 onclickcheckbox(event?:any){

if(event){
var obj={
[event.target.name] : event.target.checked
}
this.Checkvalue=Object.assign({},this.Checkvalue,obj)
}

var keys = Object.keys(this.Checkvalue);
this.filtered = keys.filter((key) => {
   return this.Checkvalue[key]
});
}


Radio buttton:
--------------

radio.json or entries array
---------------------------
[
    {
        id: 1,
        description: 'entry 1'
    },
    {
        id: 2,
        description: 'entry 2'
    },
    ...
]
---

<tbody>
          <tr *ngFor="let entry of entries">
            <td>{{ entry.description }}</td>
            <td>
                <input type="radio" name="radiogroup">
            </td>
          </tr>
        </tbody>

export class App {
    entries = []
}

Case1: Pre-select the 1st radio button of the list ==>

<tr *ngFor="let entry of entries; let idx = index">
    <td>{{ entry.description }}</td>
    <td>
        <input type="radio" name="radiogroup" [checked]="idx === 0">
    </td>
</tr>

Case2: Binding: Model -> Template ==>

<tr *ngFor="let entry of entries">
    <td>{{ entry.description }}</td>
    <td>
        <input type="radio" name="radiogroup"
            [checked]="idx === 0"
            [value]="entry.id">
    </td>
</tr>

Case3: Binding: Template -> Model ==>

<tr *ngFor="let entry of entries">
    <td>{{ entry.description }}</td>
    <td>
        <input type="radio" name="radiogroup"
            [checked]="idx === 0"
            [value]="entry.id"
            (change)="onSelectionChange(entry)">
    </td>
</tr>

@Component({...})
class App {
    entries = [];
    selectedEntry;

    onSelectionChange(entry) {
        this.selectedEntry = entry;
    }
}

Radio Button Full code:
------------------------
import {Component, NgModule} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'

@Component({
  selector: 'my-app',
  template: `
    <div>
      <h2>Binding radio buttons</h2>
   
      <p>Binding radio button lists</p>
   
      <table>
        <thead>
          <td>Description</td>
          <td></td>
        </thead>
        <tbody>
          <tr *ngFor="let entry of entries; let idx = index">
            <td>{{ entry.description }}</td>
            <td><input type="radio" name="certificategroup" (change)="onSelectionChange(entry)" [checked]="(idx === 0)" [value]="entry.value"></td>
          </tr>
        </tbody>
      </table>
   
      <hr>
   
<pre>
{{ this.selectedEntry | json }}
</pre>
   
    </div>
  `,
})
export class App {
  entries = [];
  selectedEntry: { [key: string]: any } = {
    value: null,
    description: null
  };

  constructor() {
  }

  ngOnInit() {
    this.entries = [
      {
        description: 'entry 1',
        value: 1
      },
      {
        description: 'entry 2',
        value: 2
      },
      {
        description: 'entry 3',
        value: 3
      },
      {
        description: 'entry 4',
        value: 4
      }
    ];
 
    // select the first one
    if(this.entries) {
      this.onSelectionChange(this.entries[0]);
    }
 
  }

  onSelectionChange(entry) {
    // clone the object for immutability
    this.selectedEntry = Object.assign({}, this.selectedEntry, entry);
  }

}

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

React + Typescript_ Module federation _ Micro Front end -Standalone and integrated

Module Federation The Module Federation is actually part of Webpack config. This config enables us to expose or receive different parts of t...