bhaumik shah
bhaumik shah

Reputation: 206

angular 4 min and max vlue in same input type date not working

I am trying to set min and max value to angular code here is my code

 <input type="date" 
        class="form-control" 
        style="width: 30%" 
        [disabled]="!dateSent" 
        min="{{dateSent|date:'yyyy-MM-dd'}}" 
        max="{{todaysdate|date:'yyyy-MM-dd'}}" 
        #myDate
        [value]="dateReceived | date:'yyyy-MM-dd'" 
        (input)="dateReceived=$event.target.value" />

and the value of datesent and todaydate is same

dateSent=1527445800000 and todaysdate=1527445800000 can any one help me and the out put is like this

enter image description here

thank you for your time and consideration

Upvotes: 1

Views: 8823

Answers (1)

Sravan
Sravan

Reputation: 18657

You have to take new Date(dateReceived)

Component:

import { Component,OnInit} from '@angular/core';
import { FormGroup, FormBuilder } from '@angular/forms';

@Component({
  selector: 'my-app',
  templateUrl: './app.component.html',
  styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {

  dateSent;
  dateReceived;
  todaysdate;

  ngOnInit(){
    this.dateSent="1527445800000"
    this.todaysdate="1527445800000"

  }

}

HTML:

  <input type="date" 
    class="form-control" 
    style="width: 30%" 
    [disabled]="!dateSent" 
    min="{{dateSent|date:'yyyy-MM-dd'}}" 
    max="{{todaysdate|date:'yyyy-MM-dd'}}" 
    #myDate
    [value]="dateReceived | date:'yyyy-MM-dd'" 
    (input)="dateReceived=$event.target.value" />

Here is a Working DEMO

Upvotes: 6

Related Questions