falloff
falloff

Reputation: 245

Get attribute as a object properties into directive AngularJs

I my writing universal slider directive for my app, and i need to specify that for example a control buttons in HTML code like this:

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

How can i get this values into directive as object properties for example?

Or maybe there is another way to do resuable directive? And how i can isolate this elements from parent scope?

Upvotes: 2

Views: 3538

Answers (2)

steamrunner
steamrunner

Reputation: 11

Do something like this:
scope.$watch(function () { return scope.$eval(attrs.sampleValues); }, function (newValue) {...});

Upvotes: 0

Mark Rajcok
Mark Rajcok

Reputation: 364697

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
         ...
      } 
   }
})

Upvotes: 6

Related Questions