更新时间:2023-02-26 21:26:48
您可以手动与 $解析
或范围得到插值一次。 $ EVAL
,并使用一次性绑定( {{VAR ::}}
)的模板中:
You could manually get the interpolated values once with $parse
or scope.$eval
, and use one-time binding ({{::var}}
) inside the template:
.directive('inputNumber', function ($parse) {
scope: {},
template: '<input type="number" min="{{::min}}" max="{{::max}}" ng-model="value"/>',
link: function($scope, $element, $attrs){
$scope.min = $parse($attrs.min)($scope.$parent);
$scope.max = $parse($attrs.max)($scope.$parent);
// etc...
}
}
的用法是:
<input-number data-min="min" data-max="max"></input-number>