我正在使用UI Bootstrap的datepicker函数,我想获取传入属性的值之一。Angular指令字段不需要括号
// JS
$scope.myMaxDate = new Date();
<!-- HTML -->
<input datepicker-popup="MM/dd/yyyy" max-date="myMaxDate" />
我不明白,为什么在这种情况下,max-date
ATTR需要一个字符串,而不是像{{myMaxDate}}
的表达式。它如何获得实际价值?
更重要的是,我使用装饰器来修改这个指令的一些数据,并想访问这个属性,但我得到的只是字符串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);
};
};
啊,谢谢。/10char – diplosaurus