I am using ui-bootstrap
in my application, and I found that the ui.bootstrap.datepicker
is really un-reusable. Since every date-picker have to work with a controller which control the appearance of the picker by change the isOpen
property.
So I want to enhance the input
with type of date
by adding the required attributes and controller, and I found this post useful, this is what I have done now:
function InputDirective($compile) {
var addon =
'<span class="input-group-btn">' +
'<button type="button" class="btn btn-default" ng-click="inputCtrl.open()"><i class="glyphicon glyphicon-calendar"></i></button>' +
'</span>';
return {
priority: 1000,
restrict: 'E',
controllerAs: 'inputCtrl',
controller: function($scope) {
var vm = this;
this.open = function() {
console.info("open");
vm.isopen = true;
}
},
compile: function(tElement, tAttrs) {
if (tAttrs.type != "date")
return;
console.info(tElement);
tElement.attr("datepicker-popup");
tElement.attr("is-open", "inputCtrl.isopen");
return {
pre: function preLink(scope, iElement, iAttrs, controller) {},
post: function postLink(scope, iElement, iAttrs, controller) {
iElement.after($compile(addon)(scope));
$compile(iElement)(scope);
}
}
}
};
}
However I found that compile
function will be called infinity until the browser crash.
Live example(Note the tab may be crash):
http://plnkr.co/edit/m4i4Gs4zPff0q7ykpLcG
Is it possible to fix that?