【发布时间】:2015-11-12 01:40:14
【问题描述】:
我正在使用 UI Bootstrap 的 datepicker 函数,我想获取传递给属性的值之一。
// 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);
};
};
【问题讨论】:
标签: javascript angularjs angular-ui-bootstrap