locked
problem with ngModel and databinding to Date Calendar and dropdown RRS feed

  • Question

  • User956626884 posted

    Hi,

    I am trying to use ngModel to databind to the selection made with ngbDatePicker and ngbDropDownMenu. I click on the date and when I clicked Save button, I get an alert message saying [object object]. When I databind NgModel to the dropdown, it also is not working. Any help is greatly appreciated.

    Update. I found the solution at https://ng-bootstrap.github.io/#/components/datepicker/examples

    import { HttpClient } fro 
    Friday, October 26, 2018 3:55 PM

All replies

  • User61956409 posted

    Hi comicrage,

    trying to use ngModel to databind to the selection made with ngbDatePicker and ngbDropDownMenu.

    I do a test with the following code snippet to perform binding for Datepicker via NgModel, which work for me.

    <form>
      <div class="form-group">
        <label for="dateOfBirth">Date of birth</label>
        <div class="input-group">
          <input id="dateOfBirth" class="form-control" placeholder="yyyy-mm-dd" name="dp" [(ngModel)]="model" ngbDatepicker #dp="ngbDatepicker">
          <div class="input-group-append">
            <button class="btn btn-outline-secondary calendar" (click)="dp.toggle()" type="button"></button>
          </div>
        </div>
      </div>
    </form>

    In .component.ts

    model = { 'year': 2018, 'month': 10, 'day': 23};

    Test Result:

    If possible, please share the code you are using now, so that we can check your code and help find the issue with the code.

    With Regards,

    Fei Han

    Monday, October 29, 2018 5:28 AM