1

Need to get formatted date. But following code is not working , both date and time are viewed. (need only to view the date part)

 <div class="form-group">               
       <input formControlName="startDate" type="date:'dd/MM/yyyy'" class="form-control" >
 </div>  

when type is assigned as type="date", it does not bind with the value we patched (set) .

5
  • you need to remove the other type property, you have two type property at the input element, try to remove the last one which is text. Commented Jul 26, 2017 at 6:30
  • It is not working without that as well .. Mistakenly I have added it to the post Commented Jul 26, 2017 at 6:36
  • You need to write some code on input changes Commented Jul 26, 2017 at 6:41
  • 1
    <input formControlName="startDate" type="date:'dd/MM/yyyy'" class="form-control" #date value="{{ date.value | date }}">, you can use the pipes and set it in the value of the input Commented Jul 26, 2017 at 6:45
  • The type of an input is only to instruct the browser what type of data it should expect. In case of the mobile browsers, this will change the keyboard setting to either numeric values or enable the web address version of your keyboard. It doesn't do anything with parsing or checking data, there's different methods to do so both in Angular and in HTML5. Commented Jul 26, 2017 at 6:52

1 Answer 1

1

Here are my working Plunker links for both Reactive as well as Template Driven forms

Reactive & Template

For Reactive

 <div class="form-group" formGroupName="address">
      <label for="">Date</label>
      <input type="date" class="form-control" formControlName="date">
    </div>

For Template Driven

  <div class="form-group">
    <label for="date">Date</label>
    <input type="date" class="form-control" ng-control="date" placeholder="date" required>
  </div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.