Jeethesh Kotian
Jeethesh Kotian

Reputation: 359

Date change event not getting triggered in angular

I have being working on angular 4 and not able to call a function when date changes, as code below. I am not able to call function getDateSales() when date changes.

Can someone please help in this.

Thanks in advance.

<input class="card-header-action" type="text"
                    placeholder="Select date of sales"
                    class="form-control"
                    [(ngModel)]="saleDate"
                    [bsConfig]="{ dateInputFormat: 'YYYY-MM-DD' }"
                    bsDaterangepicker
                    (change)="getDateSales()">

Upvotes: 3

Views: 4409

Answers (2)

TheParam
TheParam

Reputation: 10531

what you need here is add (bsValueChange)="onValueChange($event)" event like below

HTML

<input class="card-header-action" type="text"
                    placeholder="Select date of sales"
                    class="form-control"
                    [(ngModel)]="saleDate"
                    [bsConfig]="{ dateInputFormat: 'YYYY-MM-DD' }"
                    bsDaterangepicker
                    (bsValueChange)="getDateSales($event)">

component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'demo-datepicker-value-change-event',
  templateUrl: './value-change-event.html'
})
export class DemoDatepickerValueChangeEventComponent {
  data: Date;

  onValueChange(value: Date): void {
    this.data = value;
  }
}

Hope this will help!

Upvotes: 3

Saurabh Yadav
Saurabh Yadav

Reputation: 3386

You can subscribe to datepicker's value change event

<input class="card-header-action" type="text"
                        placeholder="Select date of sales"
                        class="form-control"
                        [(ngModel)]="saleDate"
                        [bsConfig]="{ dateInputFormat: 'YYYY-MM-DD' }"
                        bsDaterangepicker
                        (bsValueChange)="getDateSales()">

Upvotes: 1

Related Questions