Reputation: 245
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
Reputation: 11
Do something like this:
scope.$watch(function () {
return scope.$eval(attrs.sampleValues);
}, function (newValue) {...});
Upvotes: 0
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