angularjs - How to Calculate Date as per Item Shown in dropdown in Ionic2 -


i beginner in ionic 2. want calculate date per item shown in dropdown in hybrid ionic application.

i have 2 dropdown in page:

  1. first dropdown list

  1. second dropdown

enter image description here

i want, after select on last 7 days , click on **block button ** last 7 days date calculated current date, same last 1 months , last 12 months , pass days url displaying data in piecharts , bar charts

enter image description here

this home.ts code

    import { component } '@angular/core'; import { navcontroller } 'ionic-angular'; import { chartpage } '../chart/chart'; import moment 'moment'; var s,p;  @component({   selector: 'page-home',   templateurl: 'home.html' }) export class homepage {    public states: any[];   public districts: any[];   public cities: any[];   public selecteddistricts: any[];   public selectedcities: any[];   public sstate: any;   public sdistrict: any;    appname = 'dropdown app';    constructor(public navcontroller: navcontroller) {      this.initializestate();     this.initializedistrict();     this.initializecity();   }    initializestate(){   this.states = [     {id: 1, name: 'piechart'},     {id: 2, name: 'line chart'},     {id: 3, name: 'table'}   ]; }  initializedistrict(){   this.districts = [     {id: 1, name: 'last 7 days', state_id: 1, state_name: 'piechart'},     {id: 2, name: 'last 1 month', state_id: 1, state_name: 'piechart'},     {id: 3, name: 'last 12 months', state_id: 1, state_name: 'piechart'},     {id: 4, name: 'custom date', state_id: 1, state_name: 'piechart'},       {id: 5, name: 'last 7 days', state_id: 2, state_name: 'line chart'},     {id: 6, name: 'last 1 month', state_id: 2, state_name: 'line chart'},     {id: 7, name: 'last 12 months', state_id: 2, state_name: 'line chart'},     {id: 8, name: 'custom date', state_id: 2, state_name: 'line chart'},        {id: 9, name: 'last 7 days', state_id: 3, state_name: 'table'},     {id:10, name: 'last 1 month', state_id: 3, state_name: 'table'},     {id: 11, name: 'last 12 months', state_id:3, state_name: 'table'},     {id: 12, name: 'custom date', state_id: 3, state_name: 'table'}    ]; } public openmodal() {       this.navcontroller.push(chartpage);    }      initializecity(){   this.cities = [    ]; } setdistrictvalues(sstate) {      this.selecteddistricts = this.districts.filter(district => district.state_id == sstate.id)  } setcityvalues(sdistrict) {       this.selectedcities = this.cities.filter(city => city.district_id == sdistrict.id);  }  } 

this home.html

  <ion-header>   <ion-navbar>     <ion-title>{{ appname }}</ion-title>   </ion-navbar> </ion-header>  <ion-content padding> <ion-item>      <ion-label>select chart type</ion-label>      <ion-select (ionchange)="setdistrictvalues(sstate)" [(ngmodel)]="sstate">           <ion-option [value]="sstate" *ngfor = "let sstate of states">{{sstate.name}}  </ion-option>      </ion-select>   </ion-item> <ion-item *ngif="selecteddistricts">       <ion-label>duration</ion-label>       <ion-select (ionchange)="setcityvalues(sdistrict)" [(ngmodel)]="sdistrict">             <ion-option [value]="sdistrict" *ngfor = "let sdistrict of selecteddistricts">{{sdistrict.name}}</ion-option>       </ion-select>  </ion-item>    <button ion-button block (click)="openmodal()">block button</button> </ion-content> 

this provider

    import { injectable } '@angular/core'; import { http } '@angular/http'; import 'rxjs/add/operator/map';  @injectable() export class earthquakesprovider {   firstname: string;     lastname: string;    constructor(public http: http) {      console.log('hello earthquakesprovider provider');   }      loadearthquakesprovider() {         return this.http.get(`http://factoryunlock.in/sundar/public/api/v1/production`)             .map(res => res.json());     }  } 

i want create type of url in provider

http://factoryunlock.in/sundar/public/api/v1/production?from=01/02/2017&to=01/05/2017

hi can try this

var days = 7; var date = new date();  //todays datetime  milliseconds var today = date.gettime();  //get 7 days in milliseconds  var daysinmilli = (days * 24 * 60 * 60 * 1000);  //make new date 7th day var res = date.settime(today + daysinmilli );  date = new date(res);   // pass dates function below , date strings  function convertdate(date) {   var yyyy = date.getfullyear().tostring();   var mm = (date.getmonth()+1).tostring();   var dd  = date.getdate().tostring();    var mmchars = mm.split('');   var ddchars = dd.split('');    return (ddchars[1]?dd:"0"+ddchars[0]) + '/' + (mmchars[1]?mm:"0"+mmchars[0]) + '/' + yyyy; } 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -