Posts

Showing posts from June, 2019

How to update date in date picker??

Set Today's Date --> Most important thing while updating date in date picker is Date Format. Date format should be like yyyy-mm-dd . If it is not then date picker will not accept it. so first it should be convert to it using toISOString () method. <input type = "date" id = 'mydate' > <button onclick = " setcurrentdate ()" > Set Today's Date </button> <script> function setcurrentdate () { var date = new Date (); var date1 = date . toISOString (). substring ( 0 , 10 ) document . getElementById ( "mydate" ). value = date1 ; } </script>

Transfer data from one components to another using service (Angular)

Service import { Injectable } from '@angular/core' ; @Injectable () export class DataService { name=''; constructor () { } setMessage ( message : string ) { name:message } } Now most important part is to register service in Providers inside app.module . if you will declare it in every component instead of app.module then it will create new object every time and you will loss your stored value. import { BrowserModule } from '@angular/platform-browser' ; import { NgModule } from '@angular/core' ; import { FormsModule } from '@angular/forms' ; import { AppRoutingModule } from './app-routing.module' ; import { AppComponent } from './app.component' ; import { AddComponent } from './add/add.component' ; import { HomeComponent } from './home/home.component' ; import { EditComponent } from './edit/edit.component' ; import { DataSer

Call next function after previous one has been completed. (Angular)

function1 ( message ){ return new Promise (( resolve , reject ) => { console . log ( message ); resolve ( 'succsess' ); }); this . function1 ( message ). then ( data => { this . response = data ; console.log( this . response ); });

important functions for angular

Set value in local storage:- localStorage . setItem ( 'key' , ' value' ); Get value from local storage:- localStorage . getItem ( ' key ' ); call function on focus loss:- (blur)="functionName()" Loop through all the html form controls:- Object.keys(this.form.controls).forEach(key => { this.form.get(key).markAsDirty(); //this function will make dirty all the form controls });