2

我为我的应用程序编写通用滑块指令,我需要指定例如 HTML 代码中的控制按钮,如下所示:

<div class="slide-wrapper" data-sample-values="{prevbtn: '.previous', nextbtn: '.next'}"></div>

例如,如何将这些值作为对象属性放入指令中?

或者也许还有另一种方法可以执行可重复指令?以及如何将这些元素与父范围隔离?

4

2 回答 2

6
myApp.directive('slideWrapper', function() {
   return {
      restrict: 'C',
      scope: { getValues: '&sampleValues' },  // creates an isolate scope
      link:  function(scope, element, attrs) {
         var values = scope.getValues();  // evaluates expression in context of parent scope
         ...
      } 
   }
})
于 2013-02-20T20:22:29.583 回答
0

做这样的事情:
scope.$watch(function () { return scope.$eval(attrs.sampleValues); }, function (newValue) {...});

于 2014-11-23T22:21:39.713 回答