Search code examples
angularjsbootstrap-datepickerangular-strap

AngularJs AngularStrap bs-DatePicker returns undefined on ngModel


I have a problem when I try to recieve the value from ngModel in my controller. The ngModel works since it sends the value to my input when the page loads, but when I change the input value the ngModel variable turns undefined.

Html code

<input ondrop="return false" maxlength="10" type="text" class="form-
control" date-format="dd/MM/yyyy" bs-datepicker ng-
model="vm.fechaInicio"  onpaste="return false" oncut="return false" 
oncopy="return false" placement="auto bottom" container="body" 
autoclose="true" />

Controller

  vm.especialidad = {};
  vm.fechaInicio = moment();

The version of AngularJS is v1.5.9 and angular-strap is v2.3.12

Edit

I managed to work it out, the problem was that I used this in the controller and not $scope. Also I had to remove maxlength from the input.


Solution

  • Thanks for the reply Adrian Smith, I managed to work it out, the problem was that I used "this" in the controller and not $scope. Also I had to remove maxlength from the input.