I'm using UI Bootstrap's datepicker function and I'd like to get ahold of one of the values passed into an attribute.
// JS
$scope.myMaxDate = new Date();
<!-- HTML -->
<input datepicker-popup="MM/dd/yyyy" max-date="myMaxDate" />
I don't understand why in this case the max-date
attr takes a string rather than an expression like {{myMaxDate}}
. How is it getting a hold of the actual value?
What's more, I'm using a decorator to alter some data from this directive and would like to access this attribute but all I get is the string myMaxDate
.
$provide.decorator("datepickerPopupDirective", ["$delegate", function($delegate) {
// get references to the directive and old link function
var directive = $delegate[0];
var link = directive.link;
// create a new link function using compile
directive.compile = function() {
// the new link function we want to return
return function(scope, element, attrs, ngModelCtrl) {
console.log(attrs.maxDate); // 'myMaxDate'
// invoke the old link function
link.apply(this, arguments);
};
};