jose jose - 1 year ago 95
AngularJS Question

IE 11 is not triggering "ng-change" (AngularJS)

Hi all I am using

angularjs
, working with
datepicker
functionality. Input type date is not working on IE so I am using
jquery
and
css
to get date picker, it's working fine but I am not able to trigger the
ng-change
event in IE, here I attached my fiddle help. Help me solving this problem.

Fiddle

Answer Source

Internet Explorer 11 does not currently support <input type='date'> as you already trying to find a work around. You may use datepicker onSelect and update your model. You can fire change function manually. So that you can collect both changes from HTML5 Date supported browsers and others.

You can find the fiddle here

function LoginController($scope) {
    $scope.changeDetected = function() {
        console.log($scope.date);
    }

    if ($('#test')[0].type != 'date') $('#test')
        .datepicker({
            onSelect: function(date) {
                $scope.date = date;
                $scope.$apply();
                $scope.changeDetected(date);
            }
        });
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<div ng-app ng-controller="LoginController">
	<input type="date" id="test" ng-model="date" ng-change="changeDetected()"/>
  {{date}}
</div>

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