Angular 2 Materialize DatePicker

0

I have a materialize datepicker in Angular 2 and I can not get the input model

component.html

<form name="assignPeriodo_form" (ngSubmit)="assign_periodo()" >
   <div class="col m6">
      <i class="material-icons prefix">date_range</i>
      <label for="expires">Fecha Fin</label>
      <input [(ngModel)]="model.expires" id="expires" name="expires" type="date" class="datepicker" required>
   </div>
</form>

component.ts

assign_periodo(){
        console.log(this.model.expires);
}

I receive undefined all the time.

I've seen similar issues with the bs as the link but it does not work the same way link

    
asked by PriNcee 16.05.2017 в 10:25
source

1 answer

0

In most cases undefined , it will show you because you have not added data to that variable. Make sure you have initialized the variable, and that you have done it in the right place. If you use the Visual Code, it can help you a lot.

An example of Angular: link

In case you need some more concrete example, I indicate something proven in local by me, the necessary fragment:

File: fecha.component.js

model: Date;

assign_periodo(): void {
      console.log(this.model);
}

The html file:

<form name="assignPeriodo_form">
   <div class="col m6">
      <i class="material-icons prefix">date_range</i>
      <label for="model">Fecha Fin</label>
      <input [(ngModel)]="model" id="model" name="model" type="date" class="datepicker">
   </div>
</form>

<button (click)="assign_periodo()">Ver datos</button>
    
answered by 06.06.2017 в 16:46