JBenchApp.directive('jqdatepicker', function () {
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, element, attrs, ngModelCtrl) {
element.datepicker({
dateFormat: 'DD, d MM, yy',
onSelect: function (date) {
scope.date = date;
scope.$apply();
}
});
}
};
});<input type="text" ng-model="date" jdatepicker />--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/6fRdWlYLyKA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
Hi Michael,
I noticed the $scope.$apply in your directive. It does what you think, but it also refreshes every binding in your page, which may be very costly. As you have an ngModel, you don’t need it at all. I updated your fiddle a bit to show you how to use ngModelController.$setViewValue(). This is much better, as it updates only the value at hand, and will not trigger a full $digest.
Hope this helps you a bit,
Regards
Sander
--