且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Angularjs指令创建手表

更新时间: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>