crs0794 crs0794 - 1 year ago 81
AngularJS Question

Angular JS Datepicker not binding value

I have this code in my html and my input is empty without any value, although the html tag "value" has some value.

<input id="DataCompra" value="07/10/2014" class="form-control ng-pristine ng-valid"
name="DataCompra" type="text"
close-text="Fechar"
data-val="true"
data-val-date="The field Data Compra must be a date."
data-val-required="O campo Data Compra é obrigatório."
date-type="string"
datepicker-popup="dd/MM/yyyy"
is-open="DataCompra.open"
ng-click="DataCompra.open = true"
ng-model="DataCompra.dt"
show-button-bar="false"
show-weeks="false">

Answer Source

in Controller ,

$scope.DataCompra.dt = new Date('2014-10-07');

remove value attribute from the Html part,

may be this will also work,

add new directive like this

<input id="DataCompra" value="07/10/2014" ng-init="DataCompra.dt = '2014-10-07' .....

remove value attribute from the Html part,')"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download